Answer the following questions on the online google form for lab 6.
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])
sum
that returns the sum of all the odd integers
in a list of integers named nums
-- so for [1,3,2,4,5] your
expression should evaluate to 9 --- fill in the parentheses:
sum(...)
.
sum
and len
write an expression that returns
the average length of all the strings in a list of strings
named strs
. So you'll
call two list functions: one with strs
as an
argument
and one with a list comprehension using strs
as an
argument: combining in one expression
sum(...)
and len(...)
. For example,
the average length of the strings in the list below
is (3+3+4+5)/4 = 15/4 = 3.75
strs = ["cat", "dog", "bear", "tiger"]