Dictionary Flashcards

1
Q

.get()

A

Used to get the value of any specified key from a dictionary.
Example:
d.get(key) - returns value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.copy()

A

Used on objects to create copies of them
Expample: d.copy()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Enumerate function

A

Is a built in function that allows you to iterate over elements in a sequence(list, tuple, string etc) while keeping track of the index and the value of each element. Returns an enumerate object that produces pairs for index-value tuples

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Syntax for enumerate function

A

enumerate(iterable, start=0)
start is optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

dictionaries library

A

from collections import defaultdict

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Dictionary comprehension

A

animalList = [(1:a), (2:b)]
animals {key:value for key, value in animalList}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to turn a dictionary into a list

A

list(dictionary.items())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly