Python - Dictionary Methods Flashcards

1
Q

Return - none
Args - none
___________
Clears the dictionary

A

dict.clear()

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

Return - shallow copy of dictionary
Args - none
___________
returns a shallow copy of the dictionary.

A

dict.copy()

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

Return - dictionary (with keys but no values)
Args - iterable
___________
returns a new dictionary with the given sequence of elements as the keys of the dictionary.

If the value argument is set, each element of the newly created dictionary is set to the provided value.

A

dict.fromkeys(keys)

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

Return - dictionary value
Args - ( key, optional value to return if key not found)
___________
returns the value for the specified key if key is in dictionary.

A

dict.get( ‘key name’ )

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

Return - view object of key-val pairs
Args - none
___________
returns a view object that displays a list of dictionary’s (key, value) tuple pairs.

A

dict.items()

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

Return - view object of list of keys
Args - none
___________
returns a view object that displays a list of all the keys in the dictionary

A

dict.keys()

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

Return - value at specified key
Args - key
___________
removes and returns an element from a dictionary having the given key.

A

dict.pop( ‘key’ )

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

Return - view object of list of values
Args - none
___________
method returns a view object that displays a list of all the values in the dictionary.

A

dict.values()

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

Return - none
Args - another dict or some other iterable of key-val pairs (like an iterable of tuples)
___________
adds element(s) to the dictionary if the key is not in the dictionary. If the key is in the dictionary, it updates the key with the new value.

A

dict.update( dict or iterable ]

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

Return - bool
Args - iterable
___________
returns True if any element of an iterable is True. If not, any() returns False.

A

dict.any( iterable )

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

Return - bool
Args - iterable
___________
method returns True when all elements in the given iterable are true. If not, it returns False.

A

dict.all( iterable )

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

Return - none
Args - iterable of tuples
___________
constructor creates a dictionary in Python.

A

dict( [ iterable of tuples ] )

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

Return - enumerate object
Args - iterable, optional start value
___________
method adds counter to an iterable and returns the enumerate object

A

enumerate( iterable )

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

Return - list
Args - iterable, optional reverse=True
___________
method returns a sorted list from the given iterable.

A

sorted( iterable )

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