Closed leefurong closed 4 years ago
I misunderstood the Quiz. In fact we don't need to sort the data by frequency. Just use the order from the raw data is OK. Eventually I passed the Quiz via the following code.
# your code here
def append_lists(list_of_list, list_of_data):
for i, data in enumerate(list_of_data):
if len(list_of_list)<=i:
list_of_list.append([])
list_of_list[i].append(data)
def split_multi_line(s):
return list(map(lambda x: x.split(','), s.split('\n')))
def get_data(filename, ignore_heading):
print("get_data")
s = open(filename).read()
print("read s")
rows = split_multi_line(s)[1:]
print("splitted")
data_lists = []
for row in rows:
append_lists(data_lists, row)
print("finished")
return data_lists
def is_sorted(seq, by):
for i in range(0, len(seq), 2):
if not by(seq[i], seq[i+1]):
print(seq[i], seq[i+1])
return False
return True
(ranks, words, parts, freqs, dispersions) =get_data("words5000.csv", True)
total = sum(map(int, freqs))
print(total)
top_10 = sum(map(int,freqs[:10]))/float(total)
bottom_10 = sum(map(int,freqs[-10:]))/float(total)
print(top_10)
print(bottom_10)
Describe the bug It seems Activity 2 of Project 11 don't support float differences.
To Reproduce Steps to reproduce the behavior:
Go to 'Project 11
Scroll to Activity 2:
(Calculate the total usage percentage ...)
Paste the code
Expected behavior top_10 should pass, because the difference is very small. You might see the notes like this:
Screenshots
Desktop (please complete the following information):
Javascript Console Not related.