Assume that the variable grades is a list of the letters A, B, C, D, and F. For
ID: 3784252 • Letter: A
Question
Assume that the variable grades is a list of the letters A, B, C, D, and F. For example,
grades = ['A', 'F', 'C', 'F', 'A', 'B', 'A']
Write a Python expression that creates a list named, in which the elements are the number of times each of the letters A, B, C, D, and F appear in grades. For example, for the above value of grades, the following would be correct output.
frequency = [3, 1, 1, 0, 2]
Your expression must give the correct values for any list of grades, not just the one in this example. Hint: use the list method.
Explanation / Answer
>>> class test():
def handy(self):
a = raw_input('How many hands? ')
d = { "hand" + str(i + 1) : self.do_something(i) for i in range(int(a)) }
keys = d.keys()
keys.sort()
for x in keys:
print x, '=', d[x]
def do_something(self, i):
return "something " + str(i)
>>> test().handy()
How many hands? 4
hand1 = something 0
hand2 = something 1
hand3 = something 2
hand4 = something 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.