1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the keys of {"a":1,"b":2}?
["a","b"]
What are the values of {"a":1,"b":2}?
[1,2]
What will be the output of {"a":1,"b":2}["a"]?
1
What will be the output of {"a":1,"b":2}["c"]?
KeyError
How to safely access a non-existing key with a default?
dict.get("key",default)
What does {"x":10,"y":20}.get("z",0) return?
0
What is the result of len({"a":1,"b":2,"c":3})?
3
What is the output of {"p":[1,2],"q":(3,4)}["p"]?
[1,2]
Which syntax gives keys as a list?
list(dict.keys())
Which syntax gives values as a list?
list(dict.values())
What is the output type of dict.items()?
dict_items
What happens if you assign dict1["z"]=50 when dict1={"x":10}?
Adds new key-value pair
How do you remove a key from a dictionary?
del dict["key"]
What does dict.pop("x") do?
Removes key "x" and returns its value
What does dict.clear() do?
Removes all items from dictionary
What is the result of "a" in {"a":1,"b":2}?
True
What is the result of 1 in {"a":1,"b":2}?
False (checks keys, not values)
Can dictionary keys be duplicated?
No, later assignment overwrites earlier
Can dictionary values be duplicated?
Yes
Can a list be a dictionary key?
No, lists are unhashable
Can a tuple be a dictionary key?
Yes, if immutable