1/149
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
key
the immutable identity for the element in a dictionary
dictionary = {key1:value1}
format for creating a dictionary
false
true or false: dictionaries are sorted
dictionary[key]
general format for retrieving value from dictionary
true
true or false: a keyerror is returned if you call a dictionary with a nonexistent key
in
operator used to test whether a key is in a dictionary
true
true or false: dictionaries are mutable
dictionary[key]=value
format to add or change a key-pair value in a dictionary
del dictionary[key]
format to delete a key-value pair
len function
used to obtain number of elements in a dictionary
true
true or false: Values stored in a single dictionary can be of different types
dict()
built in function that creates an empty dictionary
clear method
deletes all the elements in a dictionary, leaving it empty
get method
gets a value associated with specified key from the dictionary
dictionary.get(key, default)
format for get method (returns default if key is not found)
items method
returns all the dictionaries keys and associated values; Each element in dictionary view is a tuple which contains a key and its associated value
keys method
returns all the dictionaries keys as a sequence
pop method
returns value associated with specified key and removes that key-value pair from the dictionary
dictionary.pop(key, default)
format for pop method; default is returned if key not found
popitem method
returns a randomly selected key-value pair as a tuple and removes that key-value pair from the dictionary
values method
returns all the dictionaries values as a sequence
set
object that stores a collection of data in same way as mathematical set
false
true or false: sets cannot have elements of different data types
set()
format of function used to create an empty set
‘a’,’b’,’c’
what a set contains if set(‘abc’) is passed
‘abc’
what a set contains if set([‘set’])
true
true or false: sets are mutable
add method
adds an element to a set
update method
adds a group of elements to a set
remove method
removes the specified item from the set WITH CAUSING A KEYERROR
discard method
removes the specified item from the set WITHOUT CAUSING A KEYERROR
clear method
clears all the elements of the set
union of two sets
a set that contains all the elements of both sets
set1.union(set2)
union method format
set1 l set2
operator for union method
intersection of two sets
a set that contains only the elements found in both sets
set1.intersection(set2)
format for intersection method
set1 & set2
operator for intersection method
difference of two sets
a set that contains the elements that appear in the first set but do not appear in the second set
set1.difference(set2)
difference method format
set1 - set2
difference method operator
Symmetric difference of two sets
a set that contains the elements that are not shared by the two sets
set1.symmetric_difference(set2)
symmetric_difference method format
set1 ^ set2
symmetric_difference method operator
subset
small set that is in a bigger set
superset
a large set that contains all the elements of a smaller set
setA.issubset(setB)
To determine whether set A is subset of set B
setA <= setB
To determine whether set A is subset of set B operator
setA.issuperset(setB)
To determine whether set A is superset of set B
setA >= setB
To determine whether set A is superset of set B operator
Serialize an object
convert the object to a stream of bytes that can easily be stored in a file (turning an object into computer words)
pickling
term meaning serializing an object
pickle
what you import to pickle and stuff
pickle.dump(object, file)
function to pickle objects to a file
unpickling
retrieving pickled object
pickle.load(file)
format to get pickled object from a file
{‘a’,’b’,’c’,’d’,’e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 | set2
{‘c’,’d’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 & set2
{‘a’,’b’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 - set2
{‘e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3= set2- set1
{‘a’,b’,’e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 ^ set2
sequence
an object that contains multiple items of data
list
an object that contains multiple data items and is mutible
list(object)
function converting objects to list
element
an item in a list
true
true or false lists can hold items of different types
list=[item1, item2, item3]
format for list assignment statement
repetition operator
makes multiple copies of a list and joins them together
index
a number specifying the position of an element in a list
0
index of first element in a list
-1
index of last element in a list
IndexError
raised if invalid index is used YOU CAN ONLY USE THE INDEX YOU HAVE
len function
returns the length of a sequence such as a list
eg: size = len(my_list)
mutable sequence
a sequence in which the items in the sequence can be changed
list[x] = new_value
format to assign a new value to a list element
concatenate
joining two things together
augmented assignment operator
+= used to concatenate lists
slice
a span of items that are taken from a sequence
list[start:end]
list slice format————-will not include end value
false
true or false, this will cause a IndexError
list=[1,2,3,4,5,6,7,8]
print(list[0:20])
append(item)
METHOD used to add items to a list- item is appended to the end of the existing list
index(item)
METHOD returning the index of the first element in the list containing item
-raises ValueError if item not in the list
insert(index, item)
METHOD used to insert item at position index in the list
sort()
METHOD used to sort the elements of the list in ascending order
remove(item)
METHOD used to remove the first occurrence of item in list
reverse()
METHOD used to reverse the order of the elements in the list
del list[x]
STATEMENT removing an element from a specific index in a list
min(list)
FUNCTION returning the item that has the lowest value in a sequence
max(list)
FUNCTION returning the item that has the highest value in a sequence
two-dimensional lists
a list that contains other lists as its elements
tuple
an immutable sequence
tuple_name=(item1, item2)
tuple format assignment statement
tuple(list)
turns list into tuple
cookie
a small file that contains information about the browsing session
“writing data to”
saving data on a file
output file
a file that data is written to
“reading data from”
process of retrieving data from a file
input file
a file from which data is read
open the file, process the file, close the file
the three steps when a program uses a file