Name: ______________ Net id: _____________ || Name: ______________ Net id: _____________ Name: ______________ Net id: _____________ || Name: ______________ Net id: _____________
max
returns the maximal value of a string
as well as a list. What is max("science")
and why?
reversed(sorted([5,4,1,2,8]))
and
why?
sorted(lst).index(min(lst))
for
any list lst
? Why? What's the value if
min
is replaced by max
?
str.endswith(str[-3:])
True?
st.upper().endswith(st)
True?
in
operator determines if its left operand occurs
in its right operand and returns a boolean value. This means
'a' in 'stranger'
evaluates to True. What
is the value of 5 in [1,2,3,4]
?
st[0:2] in st
is False?
st[0:2]*2 in st
is True?
lst.count(lst[0])
the same
as the value of len(lst)
for a list lst
?
print [x**2 for x in range(1,10,2)]
print [s[1] for s in ["big", "brown", "bare", "stem", "pea"]]
print ['po'*i for i in range(0,5)]
print [i*i for i in range(1,10) if i % 2 == 0]
print sum([1 for p in [1,2,3,4,5,6,7,8]])
print sum([1 for x in "ostentatiously" if "aeiou".find(x) > -1])
nums
:
strs
:
orders
rather than accessing the values directly? How do
you know?
bagelCount
?
for
loop consists of one assignment statement to
bagels
-- i.e., so that one of the three assignment
statements in the code is used and no others are used, and no if
statments are used?
orders
so that the function
bagelCount
can be written as below, where you fill
in the blank with an expression that uses variable b
:
[4,3,3,5,2]
count
?
maxPoints
using only list comprehensions
and list functions, e.g., using a transformative approach.
occs
(occurrences) values that
represent the number of occurrences
of each value 0,1,2,...,100 -- in that order-- in the
list scores
. The list created will have 101 values. You
should
use the expression range(0,101)
and the list method count
.
For example, if scores = [2,2,2,1,100]
the list
comprehension
should create occs = [0,1,3,0,0,...,0,1]
(why?)
max
, sum
, or len
and the variable
occs
--- store the maximal number of occurrences of
the mode in a variable named mode
.
findMode
. This list should use
for i in range(0,101)
and an if statement that uses values
of
occs
and the value you stored in mode
?