Python Notes
Python Notes
Len(d) returns no of items in d D[k]=v associates value v with k Del d[k] deletes item with key k K in d checks whether there is any element corresponding to key k Clear() removes all items from dictionary Copy() returns a new dictionary with same key value pairs. Deepcopy() is a method that prevents any changes from happening in the original dictionary if tried in the copied one. Fromkeys() method creates a new dictionary with the given keys each with a default corresponding value of None. Has_key() checks whether a dictionary has a given key. Items() returns all the items of the dictionary as a list of items. Iteritems() works in the same way bt returns iterator instead of list. Key() method returns a list of keys. Pop() removes key-value pair from dictionary and returns the value. Popitem() pops off the last element of a list. Setdefault() sets the value corresponding to a given key. Update() method updates one dictionary with the items of another. Values() returns a list of the values in the dictionary. A colon(:) indicates that a block of code is about to begin Endswith("string") checks whether a string ends with the given string as the argument.