programming:python:dictionary
This is an old revision of the document!
Python dictionary
| example | explanation / remarks |
|---|---|
| d = {} | empty dictionary |
| d = {“age”: 17, “school”: “Adam High School”, “transportation”: “bus”} | construct with data |
| dict[“age”]=18 | add or change value of a key |
| v = dict[“age”] | get value associated with a key |
| del dict[“school”] | delete a key,value pair based on key |
| l = len(d) | get number of keys (same as number of values…) |
| for key,val in d.items(): … | loop over all key,val pairs |
| type(d) | <class 'dict'> |
| cmp(d1, d2) | compares two dictionaries [need more info!] |
| d.clear() | delete all entries |
programming/python/dictionary.1654188523.txt.gz · Last modified: 2022/06/02 16:48 by levor
