Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dict ={'size' : 1, 'value' : 'bla'}
- #opposite as list they are not ordered!!
- dict2 ={'value' : 'bla', 'size' : 1}
- dict1 == dict2 #evaluates as True
- #they are mutable data
- 'value' in dict
- 'value' not in dict
- list(dict.keys())
- list(dict.values())
- list(dict.items())
- #iterations
- for k in dict.keys() :
- for k in dict.values() :
- for k, v in dict.items() :
- #print a set of tuple. Same as list but no square brackets, and they are immutable
- for i in dict.items() :
- if 'size' in dict
- print(dict['size'])
- dict.get('size', 0) #get the value, default if it doesn't exist
- #to be sure the key is existing, before we assign a value to it
- dict.setdefault('char', 0); #if the key is not existing add it and assign value 0, return the value otherwise
- dict[char] = 1;
- ##########################
- Data structure
- myList = [{'a' : 1, 'b' : 2}, {'c' : 1, 'd' : 2}] #list of dictionaries
Advertisement
Add Comment
Please, Sign In to add comment