Compsci 101, Counting Names
This exercise is for collaborative work during class. Do not fill out early!
Sign in to Google to save your progress. Learn more
Problem: Given a list of words, count how many times each word occurs
Solution A
def freqs(data):
    d = { }
    for word in data:
        cnt = 0
        for word2 in data:
            if word == word2:
                cnt += 1
        d[word] = cnt
    print d
How confident are you that  Solution A computes a count for each word? *
How fast is solution  Solution A if there are 8000 words? *
Solution B
def freqs2(data):
    d = {}
    for word in data:
        cnt = data.count(word)
        d[word] = cnt
    print d

How confident are you that Solution B computes a count for each word? *
How fast is solution  Solution B if there are 8000 words? *
Solution C
def freqs3(data):
    d = {}
    for word in data:
        if word not in d:
            d[word] = 0
        d[word] += 1
    print d
   

How confident are you that Solution C computes a count for each word? *
How fast is solution  Solution C if there are 8000 words? *
Names and Netids below
Names (comma separated) *
netid *
netid (partner)
netid (partner)
netid (partner)
Submit
Clear form
Never submit passwords through Google Forms.
This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Privacy Policy