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'> | 
programming/python/dictionary.1654188370.txt.gz · Last modified: 2022/06/02 16:46 by levor
                
                