Python Builtin List Function Flashcards

 

card 1 of 27

 

min( [50,20,400,30] )

 

min means minimum of the list

20

card 2 of 27

 

min( [ ] )

 

min means minimum of the list

ValueError: min() argument is an empty sequence

card 3 of 27

 

min("SimpleExamination")

 

treat the string as a list of characters

'E'

card 4 of 27

 

min( [2,'j',(3,5) ] )

 

there is not much logic to this one

2

card 5 of 27

 

max( range(20) )

 

max means maximum of the list argument

19

card 6 of 27

 

max( [ ] )

 

max means maximum of the list argument

ValueError: max() argument is an empty sequence

card 7 of 27

 

min( max(range(12,2,-1)), min(range(10,30) )

 

work out innermost parts first

SyntaxError: parentheses do not balance

card 8 of 27

 

min( max(range(12,2,-1)), min(range(10,30)) )

 

remember, min can also be a two-argument function

10

card 9 of 27

 

sum( [8,-4,2,10] )

 

sum(x) adds up the numbers in list argument

16

card 10 of 27

 

sum( [] )

 

this one has a logical answer

0

card 11 of 27

 

sum(range(5))

 

evaluate the argument first

10

card 12 of 27

 

sum("abcd")

 

you could argue this is a bug

TypeError: unsupported types for +

card 13 of 27

 

any( [False,False,False,False] )

 

any(x) returns True if any item in x is True

False

card 14 of 27

 

any( 100*[False] )

 

evaluate argument first

False

card 15 of 27

 

any( [False,False] + [True] + [False] )

 

evaluate expression for argument first

True

card 16 of 27

 

any( [ ] )

 

any(x) returns True if any item in x is True

False

card 17 of 27

 

all( [ ] )

 

all(x) returns False if any item in x is False

True

card 18 of 27

 

all( [True,True,False] )

 

all(x) returns False if any item in x is False

False

card 19 of 27

 

all( [ ] )

 

all(x) returns False if any item in x is False

True

card 20 of 27

 

all( [True] )

 

all(x) returns False if any item in x is False

True

card 21 of 27

 

all( range(20) )

 

remember Python considers 0 to be False, other numbers to be True

False

card 22 of 27

 

all( range(1,20) )

 

remember Python considers 0 to be False, other numbers to be True

True

card 23 of 27

 

all( "sample" )

 

Python considers empty strings and empty lists to be False

True

card 24 of 27

 

all( [ range(5), "one", range(5,5) ] )

 

Python considers empty strings and empty lists to be False

False
(because range(5,5) is an empty list)

card 25 of 27

 

zip([1,2,3],[99,100,101])

 

the zip(M1,M2) makes a list of pairs from two lists M1 and M2

[ (1,99), (2,100), (3,101) ]

card 26 of 27

 

zip([1,2,3,4],[99,100,101])

 

adapt the answer to the shorter list

[ (1,99), (2,100), (3,101) ]

card 27 of 27

 

zip("lookin",range(5,15)))

 

evaluate, considering the string as a list of characters

[ ('l',5), ('o',6), ('o',7), ('k',8), ('i',9), ('n',10) ]

 

End of Problem Set

(use browser reload to restart this problem set)