final Flashcards
(64 cards)
syntax for dictionary is what?
{key:value}
example of what:
p = {“p1”:”john”,”p2”:”anna”}
dictionary
do dictionaries allow duplicates, what will it do if you make duplicates
no it will overwrite existing item with same key
what accessing methods can you use for dictionary
get, keys, values, items
what does the keys() method do?
returns a list of all the keys in the dictionary
what does the values() method do?
returns a list of all the values in the dictionary
what does the items() method do?
returns items in a dictionary as tuples in a list
how do you add a single item to a dict using index
Dict[“key”] = “value”
what does the .update method do?
it adds/changes dict items
what delete methods can you use for dictionary items
pop, popitem, del, clear
what does the pop() method do
and syntax
removes item with specified key
Dict.pop(“key”)
what does popitem() do
and syntax
removes the last inserted item, does not take arguments
Dict.popitem()
what does the del method do
syntax
removes the item with specified key, or whole dictionary
del Dict[“key”]
del Dict
what does the clear method do
empties the dictionary
can you use concatentation (+) or repetition (*) on a dictionary
No
what does len() return for dictionary
the number of key-value pairs
what does sum() return for dictionary
summation of all the keys (only integers or float)
sum(Dict.values())
max() and min() returns?
the max and min keys in the dict (only if keys are the same type)
max(Dict.values())
what does sorted do?
returns a list of sorted keys in the dictionary (only if keys are not mixed)
sorted(Dict.items())
what comparison operators can you use on dictionaries
== and !=
how can you slice with a dictionary
turn it into a list and then turn it back to dict
which data structure(s) are represented by { }
set and dictionary
which data structure(s) are represented by ( )
tuple
which data structure(s) are represented by [ ]
list