Py Object Types Flashcards
Tuples, what is a Tuple suitable for?
to use as a key, since they are immutable
Tuples, how to find out a Tuple’s values?
Use the same functions as for lists,
]] < tuple_name > [ range_from : range_to ]
Mutable, which object types are mutable?
Lists, Dictionaries
Immutable, which object types are immutable?
Strings, Tuples
Dict, what is a Dict useful for?
Looking things up
Dict, what is a nested Dict?
A Dict having a Dict for Values belonging to the Key. It becomes very similar to a table
Dict, how can Values be referenced in a nested Dict?
]] for key, value in countries.items[ ]
]] print( f’ { value[ ‘capital’ ] } is the capital of
]] { key } in which they speak the language of
]] { value[ ‘capital’ ] }
Dict, what is a Dict comprehension and how is it expressed?
]] 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
List, what is a List comprehension and how is it expressed?
]] 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