Py Lists & Dicts & Tuples (Ud.10.Apps) Flashcards
how to create values 1-10 in a list without explicitly specifying each value?
}} list_1 = list( range( 1,10 ))
]] list_2
]] [1, 2, 3, 4, 5, 6, 7, 8, 9]
how to create every second value, starting from 2, between 1 and 10 into a list, without specifying each value ?
}} list_2 = list( range( 2,10,2 ))
]] list_2
]] [2, 4, 6, 8]
how to create every second value, starting from 1, between 1-10 into a list?
}} list_3 = list( range( 1,10,2 ))
]] list_3
]] [1, 3, 5, 7, 9]
how to see all functions attributable to one object type, e.g. lists?
]] dir( list )
how to find all inbuilt functions?
]] dir( __builtins__ )
how to count number of values in a list?
]] dir( list1 )
]] list1.count( 5 ) #have to provide an argument
]] 1
how to add key, value pairs to a dict?
]] dict_1 = { ‘key1’: 10.0, ‘key2’: 20.0, ‘key3’: 25.15 }
how to retrieve all values from a dict?
]] dict_1.values()
how to retrieve all keys from a dict?
]] dict_1.keys()
how to retrieve all pairs from a dict?
]] dict_1.items()
how to encapsulate values in list, dict, tuple?
]] list_1 = [ 1,2,3,4 ]
]] dict_A = { ‘A’:1, ‘B’:2, ‘C’:3, ‘D’:4 ]
]] tuple_! = ( ‘A’:1, ‘B’:2, ‘C’:3, ‘D’:4 )
what windows short command will clear the shell?
]] ctrl + < l >
create a list with 3 values and append a fourth
]] values = [ A,B,C ]
]] values.append( D )
remove the two lowest values from the list with 4 values
]] values.remove( A )
]] values.remove( B )
how do you use index for a list and what will it return?
]] values.index( D )
]] 1
– the value is expressed as an argument within fn-index and it will return the order of the value, only a single value