6. Python - Dictionaries
dictionaries: // like maps
map = {'key' = 5}
map['key']
map['newkey'] = 55 // adds a new key and value. can also change existing keys
Dictionary comprehension:
dictionary = [1,2,3,5]
test = {element: 1 for element in dictionary} // returns each number and a key and put in dictionary
Methods:
'Key' in dictionaryname // returns true or false if key is in dictionary
dictionary.keys() // return all keys
dictionary.values() // return all values
Loop Dictionaries:
for key in dictionaries:
print("{} = {}".format(key,dictionaries[key]))
Comments
Post a Comment