-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.py
More file actions
26 lines (18 loc) · 749 Bytes
/
Copy pathdict.py
File metadata and controls
26 lines (18 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Dictionnaries = “associative arrays”, indexed by keys,
# https://docs.python.org/3.4/tutorial/datastructures.html
# $Id: dict.py, c86448423bdc makhtar $
import datetime as dt
contact = {"surname": "Makhtar", "lastname": "Diouf", "phone": +12145672, "address": "Galsene sur scene",
"registration": dt.datetime.now()}
for k, v in contact.items():
print(str(k).capitalize(), ":", v)
print("-----------\n")
# Similar to
for key in sorted(contact):
print(str(key).capitalize(), ":", contact[key])
print("-----------\n")
print("tel" in contact, list(contact.keys()))
# builds dictionaries directly from sequences of key-value pairs
d = dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
print(d)
# See keyvalues.py