Lists, Tuples, Dictionaries, and Sets Flashcards
what command do we use to add multiple new elements to a list?
listname.extend([item 1, item 2])
what command do we use when we want to add one new nested element to a list?
listname.append([item 1, item 2])
what is the major difference between lists and tuples?
list items can be individually changed by using listname[item number] = new value
tuples cannot be changed, but instead a new variable must be made such as sortedtuple
what command removes a single item from a list
del listname[0]
true or false: if you have aliased lists and you change an item on list A, it will change on list B
true - they are both pulling from the same object
clone the list to fix the problem
what is the command to clone a list
B = A[:]
how do you sort the values in a tuple
newtuple = sorted(tuple)
how do you access the nested tuple within a tuple
tuple[1][2]
how do you locate the index of a particular string or item?
tuplename.index(“item name”)
how do you create a dictionary?
Dict = {key1:value 1, key 2:value 2}
how do you recall a value from the dictionary using its key
Dict[“key1”]
what is the command to get all the keys in a dictionary?
dictionaryname.keys()
what is the command to get all the values in a dictionary?
dictionaryname.values()
how do you add a key value pair into a dictionary?
dictionaryname[“new key”] = “new value”
how do we delete an entry in a dictionary with its key
del(dictionaryname[“key”])