| Reply | « Previous Thread | Next Thread » |
|
hi guys im trying to make the words that have capital letters in small caps, then count the numbers of times a certain words appears in the text.
i managed to count the number of times a word appears but now im having trouble converting upperletters to caps on all words. here is my code: Code:
words = {}
file = open ('input.txt', 'r')
for line in file:
wordlist = line.split()
for word in wordlist:
if words.upper(word):
words[word]=words.lower(word) #<<< not working for conversion but not sure.
if words.has_key(word):
words[word]=words[word]+1
else:
words[word] = 1
for word in words:
print word, words[word]words = {}
|
|
I could be wrong, but words is a dict and dict does not have a lower method. Are you looking to do this perhaps?
Code:
words[word] = word.lower(word) Code:
words[word] = word.lower()
Last edited by raf1hh : 2008-12-07 at 07:03.
Reason: Afterthought
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Testers for free OCR program wanted | caddydc2 | News, Announcements and Job Listings | 1 | 2008-05-05 18:52 |
| Arguments for Python executable? | thetao | Python | 9 | 2008-04-04 21:41 |
| (Re)associating Python scripts with Python in messaging? | RaimondasL | Python | 3 | 2007-03-13 07:50 |
| I can't to Minimize program (Imprement by python) | asimo_san | Python | 2 | 2007-02-16 18:35 |
| a simple program help | phelgm | Mobile Java General | 1 | 2004-01-26 18:27 |