Created
July 5, 2011 19:20
-
-
Save acrymble/1065633 to your computer and use it in GitHub Desktop.
Python count items in a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# count-list-items-1.py | |
wordstring = 'it was the best of times it was the worst of times ' | |
wordstring += 'it was the age of wisdom it was the age of foolishness' | |
wordlist = wordstring.split() | |
wordfreq = [] | |
for w in wordlist: | |
wordfreq.append(wordlist.count(w)) | |
print "String\n" + wordstring +"\n" | |
print "List\n" + str(wordlist) + "\n" | |
print "Frequencies\n" + str(wordfreq) + "\n" | |
print "Pairs\n" + str(zip(wordlist, wordfreq)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I receive this message when I attempt pair the wordlist with the wordfreq: zip object at 0x7fc040754948
What does this mean?