python dictinory

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards

What are the keys of {"a":1,"b":2}?

["a","b"]

2
New cards

What are the values of {"a":1,"b":2}?

[1,2]

3
New cards

What will be the output of {"a":1,"b":2}["a"]?

1

4
New cards

What will be the output of {"a":1,"b":2}["c"]?

KeyError

5
New cards

How to safely access a non-existing key with a default?

dict.get("key",default)

6
New cards

What does {"x":10,"y":20}.get("z",0) return?

0

7
New cards

What is the result of len({"a":1,"b":2,"c":3})?

3

8
New cards

What is the output of {"p":[1,2],"q":(3,4)}["p"]?

[1,2]

9
New cards

Which syntax gives keys as a list?

list(dict.keys())

10
New cards

Which syntax gives values as a list?

list(dict.values())

11
New cards

What is the output type of dict.items()?

dict_items

12
New cards

What happens if you assign dict1["z"]=50 when dict1={"x":10}?

Adds new key-value pair

13
New cards

How do you remove a key from a dictionary?

del dict["key"]

14
New cards

What does dict.pop("x") do?

Removes key "x" and returns its value

15
New cards

What does dict.clear() do?

Removes all items from dictionary

16
New cards

What is the result of "a" in {"a":1,"b":2}?

True

17
New cards

What is the result of 1 in {"a":1,"b":2}?

False (checks keys, not values)

18
New cards

Can dictionary keys be duplicated?

No, later assignment overwrites earlier

19
New cards

Can dictionary values be duplicated?

Yes

20
New cards

Can a list be a dictionary key?

No, lists are unhashable

21
New cards

Can a tuple be a dictionary key?

Yes, if immutable