You Are Here:

Community: Developer Discussion Boards

#1 Old python program help - 2008-12-07, 05:55

Join Date: Dec 2008
Posts: 1
jvignacio
Offline
Registered User
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 = {}
thank u!
Reply With Quote

#2 Old Re: python program help - 2008-12-07, 07:02

Join Date: Nov 2007
Posts: 117
raf1hh
Offline
Regular Contributor
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)
in which case you might want to do this:

Code:
words[word] = word.lower()
Last edited by raf1hh : 2008-12-07 at 07:03. Reason: Afterthought
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia