Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
18 Cards in this Set
- Front
- Back
Examples of unordered collections |
Dictionaries = {key : value} Sets = {list} |
|
d = {"apple" : "red", "Lemon":"yellow", "lime":"green"} d["banana"] = "yellow" |
A dictionary is bein initialized with fruit as keys and their colors as the values. Then we proceed to create a new element into the dictionary. |
|
del d["banana"] |
it deletes the element banana from the d dictionary. |
|
d.clear() |
it erases every element from the d dictionary. |
|
d.get("something") ??? |
it returns whatever the key was given. |
|
why is it not a good idea to add or delete elements while iterating through a dictionary? |
It is not a good idea because each time an item is added or deleted the order of the dictionary changes. |
|
d = {"apple" : "red", "Lemon":"yellow", "lime":"green"} order_keys = list(d.keys()) order_keys.sort() for f in order_keys: print(f + " is " + d[f]) |
This is a way of making sure that we iterate through the dictionary in a sorted manner, every single time. |
|
d_tuple = tuple(d.items()) |
it creates a tuple that has tuples as their values. Each tuple has the key and the values of the each dictionary element. |
|
for a in d_tuple: fruit, color = a print(fruit + " is " + color) |
it is unpacking a tuple and assigning their values to variables fruit and color. |
|
what does the .join() function do? |
It lets us add text to every block of text in a variable. Better explanation needed. |
|
what does the .copy() function do when use on a dictionary? |
It creates a copy of the dictionary that is being inputed without modifying the data of the dictionary. |
|
what does the .update() function do when use on a dictionary? |
it adds two dictionaries together. Thus modifying the dictionary that is being updated. |
|
How is a set initialize? |
It can be initialize in two ways. s = set(1,2,3,4,5) //This way a set can be intialize with zero items. s = {1, 2, 3, 4} |
|
What does the union() function do on functions. |
It returns the union of two sets. EXAMPLE: un = s.union(other_set) |
|
What does the & and intersection function do? |
They return the values that are present in both sets. EXAMPLE: un |
|
what does the difference function do to a set. |
It returns the values of the set minus the set that is being inputed to the difference function. example even.difference(squares) returns the values of even minus the values of squares. |
|
what does the symmetric_difference() function do on a set? |
It returns the result of both dictionaries join together without the values that appear on both dictionaries. It does the opposite of & and joins the dictionaries together. |
|
what is a frozen set? |
It is a set that is immutable. |