1/32
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
dictionary
object that stores a collection of data, consists of a key and value
retrieve value
dictionary_name[key]
add elements
dictionary[key]=value
delete elements
del dictionary[key]
len function
empty dictionary
use {}
for loop
for key in dictionary:, for item in set:
clear method
deletes all the elements in a dictionary, leaving it empty (dictionary.clear())
get method
gets a value associated with specified key from the dictionary (dictionary.get(key, default))
items method
returns all the dictionaries keys and associated values (dictionary.items())
keys method
returns all the dictionaries keys as a sequence (dictionary.keys())
pop method
returns value associated with specified key and removes that key-value pair from the dictionary (dictionary.pop(key, default))
popitem method
Returns, as a tuple, the key-value pair that was last added to the dictionary, also removes the key-value pair from dictionary (dictionary.popitem())
values method
returns all the dictionaries values as a sequence (dictionary.values())
dictionary comprehension
an expression that reads a sequence of input elements and uses those input
elements to produce a dictionary (squares={item**2 for item in numbers})
set
object that stores a collection of data in same way as mathematical set (mutable)
set function
used to create a set, empty set call set(), non-empty call set(argument)
len function
returns the number of elements in the set
add method
adds an element to a set
update method
adds a group of elements to a set, elements must be iterable
remove + discard methods
remove the specified item from the set, remove raises KeyError, discard does not
clear method
clears all the elements of the set
in operator
used to test whether a value exists in set, not in as well
union of two sets
a set that contains all the elements of both sets (set3=set1.union(set2) or set1 | set2)
intersection of two sets
a set that contains only the elements found in both sets (set3=set1.intersection(set2) or set1 & set2)
difference of two sets
a set that contains elements that appear in the first set but do not appear
in second set (set3=set1.difference(set2) or set1-set2)
symmetric difference of two sets
a set that contains the elements that are not shared by the two sets (set1.symmetric_difference(set2) or set1^set2)
subset
Set A is subset of set B if all the elements in set A are included in set B (setA.issubset(setB) or setA <= setB)
superset
Set A is superset of set B if it contains all the elements of set B (setA.issuperset(setB) or setA >= setB)
set comprehension
a concise expression that creates a new set by iterating over the elements of a
sequence (set2={item for item in set1})
serialize an object
convert the object to a stream of bytes that can easily be stored in a file
pickling
serializing an object, import pickle (pickle.dump(object, file)) then close
unpickling
retrieving pickled object, import pickle then open file (pickle.load(file)) then close