52. Dictionary keys Flashcards

1
Q

can dictionary put a dictionary key in a dictionary to print, example
‘[100]’ : True

print (dictionary[100])

A

usually has to be a spirng plus this will not print :(

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

what does .get

A
  • method on object or method,
  • use if you want to look for a the right hand side
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what if you use .get, how do you add a default value?

A

-user.get(‘age’, 55))

in this example the user is the name of the dictionary. get is the mthod, age is the left hand, see if you have tha to see the left side, if not the default is 55

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

What is another way to do a dictionary?

A

user 2 = dict(name= ‘JohnJohn’)
print(user2)
prints: {‘name’: ‘JohnJohn’

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

what does .keys do?

A

-checks keys, ON THE LEFT side, if it is there

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

what does .values do?

A

does over right side and says if it is true.

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

what does clear do?

A

empty object :)

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

what does user. copy do?

A

copies the first copy, and cfretes two copies, but if you erase the first one, you have the second one

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

what does .update do when you write
print(user.update([‘ages’: 55]))

A
  • it updates the key value
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly