Py Object Types Flashcards

1
Q

Tuples, what is a Tuple suitable for?

A

to use as a key, since they are immutable

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

Tuples, how to find out a Tuple’s values?

A

Use the same functions as for lists,

]] < tuple_name > [ range_from : range_to ]

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

Mutable, which object types are mutable?

A

Lists, Dictionaries

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

Immutable, which object types are immutable?

A

Strings, Tuples

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

Dict, what is a Dict useful for?

A

Looking things up

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

Dict, what is a nested Dict?

A

A Dict having a Dict for Values belonging to the Key. It becomes very similar to a table

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

Dict, how can Values be referenced in a nested Dict?

A

]] for key, value in countries.items[ ]
]] print( f’ { value[ ‘capital’ ] } is the capital of
]] { key } in which they speak the language of
]] { value[ ‘capital’ ] }

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

Dict, what is a Dict comprehension and how is it expressed?

A

]] new_dict = dict( counter( sherlock_holmes() )
]] new_dict = { k:v for k,v in new_dict.items{ } if
]] k.isalpha() }
– creates a new DIct only including values being
– alphanumeric

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

List, what is a List comprehension and how is it expressed?

A

]] L = [ x**2 for x in range( 1,11 ]

    • creates a list with values in power of the numbers
    • specified in the range, excluding 11
How well did you know this?
1
Not at all
2
3
4
5
Perfectly