File Read Operation with counting each words in the file

This is the place for queries that don't fit in any of the other categories.

File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 4:37 pm

NOTE: To be done without Python Classes Usage!

I tried the following code, okay firstly I studied file operation today itself, with it a lot of dict & strings doubts get solved. What I tried was counting the total no. of individual words, store them string by string in a dictionary dicword, (after import codec 1st),

Code: Select all
f = codecs.open('C:\Users\Hero\Documents\singapore.txt','rU','utf-8')

dictxt={}
count=0
for line in f:   ## iterates over the lines of the file
    dictxt[count]=line,
    print line,
    count+=1
f.close()
print line


then run a test of stored item in dicword from dictxt as below:

Code: Select all
for key,value in dictxt.items():
    #print key,value
    for string in value:
        #print string
        if word!=string:
            for string in dicword.values():
                newcount+=1
            count=newcount+1
            word=string
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            newcount=0
            count=0
            tempno=0
        else:
            tempelif+=1
            count=tempelif
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            count=0
print dicword


As for the full code:

Code: Select all
f = codecs.open('C:\Users\Hero\Documents\singapore.txt','rU','utf-8')

dictxt={}
count=0
for line in f:   ## iterates over the lines of the file
    dictxt[count]=line,
    print line,
    count+=1
f.close()
print line
majorcount=0
word=0
index=0
count=0
a=0
newcount=0
#dicnu={}
dicword={}
tempno=0
tempelif=0
for key in dictxt.keys():
    a+=1
#tuplee=[]
for key,value in dictxt.items():
    #print key,value
    for string in value:
        #print string
        if word!=string:
            for string in dicword.values():
                newcount+=1
            count=newcount+1
            word=string
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            newcount=0
            count=0
            tempno=0
        else:
            tempelif+=1
            count=tempelif
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            count=0
print dicword


But the output was something like this for the file "Singapore.txt".
NOTE: The input file had quite a few words so I have copied & pasted the whole error part. The file is attached so you can try for yourself & tell me what the goodie am I doing wrong.

Q1: this is not the way I think dicword should have printed.isn't it supposed to print like key:value??
Q2: the code runs in 1st attempt! but then some error crops up. So why did the code run like following at all, & why does it not show in the dictionary format
Q3: Can anyone explain what do the arrowed errors mean in simpler terms?

Firstly, as u are not trained in Singapore, any family physician or specialist will be conditionally registered only.You will be "supervised" when working in a hospital. Full fledged specialist in their country cannot practice as consultant ( or attendings ). You will start off as a registrar ( or resident) Unfortunately, you cannot immediately setup a private practice.

For family physicians ( General practitioners, or GP as we call them that here), the typical supervision period is about 4 years before an endorsement from ur supervisor earns u the full registeration. For specialist it's usually 2 years. Google for SMC singapore registerable qualifications to see the list of specialist certs recognised / or basic MBBS/MD for general practitioners.

You can also google for Singapore General hospital, tan tock Seng hospital, Changi Hospital to look up the careers section to find people to contact. Generally, it's easier to come here to work if you contact them

There is no shortage of private GP clinic all around. In any neighborhood, the ratio of GPs to a grocery stores is about 1:1. A survey done in 2006 shows the average net income for a private GP to be about 120K/pa ( sing $$ ). The only issue is that a prior survey done in 1996 show an annual salary of about $120K/pa too. That means that accounting for inflation, GP salary actually drop over the 10 year period.

Senior GP in government hospital gets abotu 8K/per mth ( but they received a form of compulsory savings contribution and bonus + leave etc, so it sorta evens out with private sector). Of course, the private GP can offer other things, amongst which are aesthetic medicine. Some business savvy GPs also set up practise in young estates focusing on child health. "Examplary" cases of private GPs who evaded $11 million in tax over 5 years was all over the newspapers years ago.
However the workload is quite different. Gov GPs are overloaded, a few years ago, they reported seeing up to 100 patients a day compared to about 30-40 for private GP. Nowadays, with more graduates and overseas docs, it drop to about 50 patients a day. We are also utilising APN( advance practising nurses, similar to Physician assistants in the US ) that can carry out simpler duties of a GP, ( like take BP, etc). It looks to improve as gov is increasingly
aware of the need to have a strong primary care force as the population gets older.

Ok. so with a 10K/per mth pay, what the standard of living like? Cars are expensive, but EVERYONE in this thread fail to mention that public transport here is good( trains, bus, taxis) It's a small place and quite efficient, so you do not really need a car. If you do need a car, a jap made will cost you about 1.2K/mth, which is not too bad at 10%. Food ranges from $2.5 ( YES, $2.5) for the fill up your stomach type to $20 for a simple course at a eatery.
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-82-1a71c5571578> in <module>()
1 dictxt={}
2 count=0
----> 3 for line in f: ## iterates over the lines of the file
4 dictxt[count]=line,
5 print line,

C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\codecs.pyc in next(self)
682
683 """ Return the next decoded line from the input stream."""
--> 684 return self.reader.next()
685
686 def __iter__(self):

C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\codecs.pyc in next(self)
613
614 """ Return the next decoded line from the input stream."""
--> 615 line = self.readline()
616 if line:
617 return line

C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\codecs.pyc in readline(self, size, keepends)
528 # If size is given, we call read() only once
529 while True:
--> 530 data = self.read(readsize, firstline=True)
531 if data:
532 # If we're at a "\r" read one extra character (which might

C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\codecs.pyc in read(self, size, chars, firstline)
475 data = self.bytebuffer + newdata
476 try:
--> 477 newchars, decodedbytes = self.decode(data, self.errors)
478 except UnicodeDecodeError, exc:
479 if firstline:

UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 89: invalid start byte
Last edited by lovecodecakes on Wed Feb 13, 2013 5:08 pm, edited 2 times in total.
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby stranac » Wed Feb 13, 2013 6:42 pm

It looks like utf-8 is not the correct encoding for that file.
The reason it works for a few lines is it only encounters a character it can't decode as utf-8 later in the file.

It's not the dict that is printed, it's individual lines that you print with
Code: Select all
    print line,


Also, your code looks over-complicated.
For example, there is no need to use a dict for the file's lines, you seem to be looping the dict just to get it's length, and similar stuff.

And you shouldn't be running your scripts with ipython, as the output(as well as the error traceback) is often different from what normal python would give you.

Btw, I enabled a few more file types for attachments, so you can attach the actual file now.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 6:56 pm

Here is the original txt file

Q: What would be happening when print dicword is being given out at the last?
And how would you suggest to uncomplicate it?


stranac wrote:It looks like utf-8 is not the correct encoding for that file.
The reason it works for a few lines is it only encounters a character it can't decode as utf-8 later in the file.

It's not the dict that is printed, it's individual lines that you print with
Code: Select all
    print line,


Also, your code looks over-complicated.
For example, there is no need to use a dict for the file's lines, you seem to be looping the dict just to get it's length, and similar stuff.

And you shouldn't be running your scripts with ipython, as the output(as well as the error traceback) is often different from what normal python would give you.

Btw, I enabled a few more file types for attachments, so you can attach the actual file now.
Attachments
singapore.txt
The original txt file
(10.23 KiB) Downloaded 124 times
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby stranac » Wed Feb 13, 2013 7:12 pm

Ok, that doesn't look like a utf8 encoded file at all.
You shouldn't use codecs.open() to open it, you can just use he built-in open() function.

lovecodecakes wrote:Q: What would be happening when print dicword is being given out at the last?

You just need to fix your code and see for yourself.
But if I understood your first code correctly, it would pretty much look like you expected.

lovecodecakes wrote:And how would you suggest to uncomplicate it?

That depends on what the code is actually meant to do, but a few things are:
  • You don't need a dict for storing the file's lines. You can use a list, or just do stuff with lines as you loop the file
  • You have a count variable in the for loop, but you reset it to 0 without using it
  • The variables you're creating might not all be needed, but it's hard to tell since I don't know why you're creating them
I can't say much about the rest of the code, since I don't know what you're actually trying to do.
If you explain that, maybe I can give you some more suggestions.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 7:19 pm

Ok, without the utf-8 argument set, it's like this:
It is printing the dictionary dicword

Code: Select all
dictxt={}
count=0
for line in f:   ## iterates over the lines of the file
    dictxt[count]=line,
    #print line,
    count+=1
f.close()
#print line,
majorcount=0
word=0
index=0
count=0
a=0
newcount=0
#dicnu={}
dicword={}
tempno=0
tempelif=0
for key in dictxt.keys():
    a+=1
#tuplee=[]
for key,value in dictxt.items():
    #print key,value
    for string in value:
        #print string
        if word!=string:
            for string in dicword.values():
                newcount+=1
            count=newcount+1
            word=string
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            newcount=0
            count=0
            tempno=0
        else:
            tempelif+=1
            count=tempelif
            dicword[word]=count
            #dicnu[key]=tuplee
            #tuplee=(dicnu,dicword)
            count=0
print dicword


But it's still weird. O/P:
{1: 3, 'Firstly, as u are not trained in Singapore, any family physician or specialist will be conditionally registered only.You will be "supervised" when working in a hospital. Full fledged specialist in their country cannot practice as consultant ( or attendings ). You will start off as a registrar ( or resident) Unfortunately, you cannot immediately setup a private practice.\n': 1}

it's like first key =>1
second key is not key but a whole string of sentences to which the value is 1...


stranac wrote:It looks like utf-8 is not the correct encoding for that file.
The reason it works for a few lines is it only encounters a character it can't decode as utf-8 later in the file.

It's not the dict that is printed, it's individual lines that you print with
Code: Select all
    print line,


Also, your code looks over-complicated.
For example, there is no need to use a dict for the file's lines, you seem to be looping the dict just to get it's length, and similar stuff.

And you shouldn't be running your scripts with ipython, as the output(as well as the error traceback) is often different from what normal python would give you.

Btw, I enabled a few more file types for attachments, so you can attach the actual file now.
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 7:29 pm

Unused variables>ignore.

logic is:
wird=0
for key, value in dictionary items
for strings in values/key
if word != strings
then for strings in dicword.values():
start a counter
(if there were those strings found earlier in dicword count=counter value
if not found count = counter+1 #counter=0 initially & reset to 0 at the end of this for loop) which is count=newcount+1
under the same indentation below for loop means its not under for loop so:
condition was if word!=strings, in any case word=strings
dicword[key which is word]=count
reset count
reset newcount counter

else: if word ==strings
another count increment
count=pointing to this tempelif value
finally dicword[key which is word]=count
reset count

The point if if the same word was found it would increment
if not found which will be the usual case in a sentence,search for it in the dictionary,add the counts from this counter and replace else just add this new word to dict with count=1
Repeat.

stranac wrote:Ok, that doesn't look like a utf8 encoded file at all.
You shouldn't use codecs.open() to open it, you can just use he built-in open() function.

lovecodecakes wrote:Q: What would be happening when print dicword is being given out at the last?

You just need to fix your code and see for yourself.
But if I understood your first code correctly, it would pretty much look like you expected.

lovecodecakes wrote:And how would you suggest to uncomplicate it?

That depends on what the code is actually meant to do, but a few things are:
  • You don't need a dict for storing the file's lines. You can use a list, or just do stuff with lines as you loop the file
  • You have a count variable in the for loop, but you reset it to 0 without using it
  • The variables you're creating might not all be needed, but it's hard to tell since I don't know why you're creating them
I can't say much about the rest of the code, since I don't know what you're actually trying to do.
If you explain that, maybe I can give you some more suggestions.
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby metulburr » Wed Feb 13, 2013 7:44 pm

What I tried was counting the total no. of individual words, store them string by string in a dictionary

Yours looks overly complicated

This is a basic setup of what "i think" your looking for
Code: Select all
words = {}
f = open('test.txt')
data = f.read()

for word in data.split():
   try:
      words[word] += 1
   except KeyError:
      words[word] = 1
   
print(words)


The whole thing is based off f.read().split(), which splits the entire string of the text file into a list of words indexed by the space in the file. At that point if your want, you can strip off puncuation, etc.

The try/except is there because if you rearrange their statments, it will reassign whatevger value it "was" at to 1, losing the data, instead it first tries to add 1 to the value of that key, if the key doesnt exist, it gets a keyerror, at that point moves to the except and creates that key with value of one, so the next time around if it comes across that word, it increments it, and bypasses the except
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1562
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 7:52 pm

that's a wow.
didn't know about this "try" & "except" & "KeyError"
you created a words dictionary & dictionaries can increment??

metulburr wrote:
What I tried was counting the total no. of individual words, store them string by string in a dictionary

Yours looks overly complicated

This is a basic setup of what "i think" your looking for
Code: Select all
words = {}
f = open('test.txt')
data = f.read()

for word in data.split():
   try:
      words[word] += 1
   except KeyError:
      words[word] = 1
   
print(words)


The whole thing is based off f.read().split(), which splits the entire string of the text file into a list of words indexed by the space in the file. At that point if your want, you can strip off puncuation, etc.

The try/except is there because if you rearrange their statments, it will reassign whatevger value it "was" at to 1, losing the data, instead it first tries to add 1 to the value of that key, if the key doesnt exist, it gets a keyerror, at that point moves to the except and creates that key with value of one, so the next time around if it comes across that word, it increments it, and bypasses the except
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Wed Feb 13, 2013 7:55 pm

yea you got me right with that try & except thing.

lovecodecakes wrote:that's a wow.
didn't know about this "try" & "except" & "KeyError"
you created a words dictionary & dictionaries can increment??

metulburr wrote:
What I tried was counting the total no. of individual words, store them string by string in a dictionary

Yours looks overly complicated

This is a basic setup of what "i think" your looking for
Code: Select all
words = {}
f = open('test.txt')
data = f.read()

for word in data.split():
   try:
      words[word] += 1
   except KeyError:
      words[word] = 1
   
print(words)


The whole thing is based off f.read().split(), which splits the entire string of the text file into a list of words indexed by the space in the file. At that point if your want, you can strip off puncuation, etc.

The try/except is there because if you rearrange their statments, it will reassign whatevger value it "was" at to 1, losing the data, instead it first tries to add 1 to the value of that key, if the key doesnt exist, it gets a keyerror, at that point moves to the except and creates that key with value of one, so the next time around if it comes across that word, it increments it, and bypasses the except
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby metulburr » Wed Feb 13, 2013 8:01 pm

there are other ways to do the same without the try/except way too.

you created a words dictionary & dictionaries can increment??

words is the dict, word is the key, which is each word in string (which will include the punctuation, etc.), and the value is an integer, which of course can increment, which is the count of each key (word) in the file
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1562
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: File Read Operation with counting each words in the file

Postby Yoriz » Wed Feb 13, 2013 9:46 pm

Code: Select all
import re
from collections import Counter


def countWords(fileName):
    words = []
    with open(fileName, 'r') as readFile:
        for line in readFile:
            for word in re.findall(r'[A-Za-z]+', line):
                words.append(word)
    return Counter(words)

print countWords('singapore.txt')

Counter({'': 2578, 'a': 52, 'the': 50, 'to': 41, 'of': 38, 'in': 31, 'for': 25, 'about': 21, 'is': 20, 'K': 16, 'medical': 16, 'that': 15, 'are': 14, 'Medical': 14, 'you': 14, 'and': 13, 'as': 13, 'be': 11, 'or': 11, 'with': 11, 'private': 10, 'Singapore': 10, 'at': 10, 's': 9, 'registration': 9, 'all': 8, 'GP': 8, 'more': 8, 'not': 8, 'an': 8, 'it': 8, 'specialist': 7, 'from': 7, 'years': 7, 'The': 7, 'will': 7, 'up': 7, 'u': 7, 'here': 6, 'SMC': 6, 'hospital': 6, 'sg': 6, 'good': 6, 'University': 6, 'have': 6, 'who': 6, 'College': 6, 'on': 6, 'www': 6, 'i': 6, 'school': 5, 'few': 5, 'can': 5, 'how': 5, 'year': 5, 'qualification': 5, 'need': 5, 'GPs': 5, 'etc': 5, 'com': 5, 'like': 5, 'per': 5, 'Health': 4, 'this': 4, 'if': 4, 'so': 4, 'them': 4, 'Medicine': 4, 'I': 4, 'There': 4, 'any': 4, 'also': 4, 'which': 4, 'do': 4, 'country': 4, 'relevant': 4, 'basic': 4, 'has': 4, 'You': 4, 'It': 4, 'contact': 4, 'yes': 4, 'Ok': 4, 'Sciences': 4, 't': 4, 'mth': 4, 'income': 4, 'very': 3, 'list': 3, 'cost': 3, 'General': 3, 'typical': 3, 'over': 3, 'course': 3, 'MIT': 3, 'actually': 3, 'practice': 3, 'day': 3, 'practising': 3, 'out': 3, 'medicine': 3, 'gov': 3, 'million': 3, 'one': 3, 'postgraduate': 3, 'salary': 3, 'm': 3, 'local': 3, 'where': 3, 'For': 3, 'we': 3, 'simple': 3, 'dun': 3, 'recognised': 3, 'child': 3, 'And': 3, 'doctor': 3, 'practise': 3, 'employment': 3, 'by': 3, 'http': 3, 'was': 3, 'but': 3, 'compared': 3, 'under': 2, 'me': 2, 'surgeon': 2, 'smc': 2, 'small': 2, 'work': 2, 'what': 2, 'section': 2, 'public': 2, 'degree': 2, 'reported': 2, 'kids': 2, 'prior': 2, 'survey': 2, 'family': 2, 'ask': 2, 'licensing': 2, 'working': 2, 'criteria': 2, 'must': 2, 'car': 2, 'Pte': 2, 'address': 2, 'tax': 2, 'information': 2, 'place': 2, 'A': 2, 'may': 2, 'cannot': 2, 'before': 2, 'Delhi': 2, 'they': 2, 'possess': 2, 'In': 2, 'drop': 2, 'suprise': 2, 'Council': 2, 'shortage': 2, 'practitioner': 2, 'registrable': 2, 'raffles': 2, 'issue': 2, 'births': 2, 'quite': 2, 'Maharashtra': 2, 'isn': 2, 'first': 2, 'Universities': 2, 'nhg': 2, 'done': 2, 'directly': 2, 'Website': 2, 'practitioners': 2, 'singhealth': 2, 'least': 2, 'their': 2, 'too': 2, 'national': 2, 'listed': 2, 'B': 2, 'population': 2, 'depends': 2, 'patients': 2, 'Generally': 2, 'bring': 2, 'much': 2, 'should': 2, 'only': 2, 'ones': 2, 'earn': 2, 'bad': 2, 'she': 2, 'Education': 2, 'med': 2, 'Hospital': 2, 'best': 2, 'That': 2, 'sorta': 2, 'come': 2, 'annual': 2, 'lokun': 2, 'Ltd': 2, 'period': 2, 'Lol': 2, 'expensive': 2, 'due': 2, 'look': 2, 'these': 2, 'pay': 2, 'gets': 2, 'temporary': 2, 'singapore': 2, 'hand': 2, 'well': 2, 'OBGY': 2, 'world': 2, 'know': 2, 'google': 2, 'people': 2, 'back': 2, 'Institute': 2, 'schedule': 2, 'each': 2, 'would': 2, 'housemanship': 2, 'your': 2, 'question': 2, 'start': 2, 'pa': 2, 'complete': 2, 'offer': 2, 'registered': 2, 'he': 2, 'wish': 2, 'ur': 2, 'similar': 2, 'field': 2, 'other': 2, 'ago': 2, 'land': 2, 'EVERYONE': 1, 'evidence': 1, 'consider': 1, 'Madras': 1, 'Parents': 1, 'salaries': 1, 'GMTI': 1, 'whose': 1, 'Non': 1, 'attentive': 1, 'granting': 1, 'opthamolgist': 1, 'young': 1, 'opportunities': 1, 'chaps': 1, 'those': 1, 'Physician': 1, 'Zzzz': 1, 'definetly': 1, 'advised': 1, 'GI': 1, 'evaded': 1, 'applicable': 1, 'leave': 1, 'He': 1, 'its': 1, 'neighborhood': 1, 'ortho': 1, 'recruitment': 1, 'Blk': 1, 'registeration': 1, 'internship': 1, 'goes': 1, 'net': 1, 'full': 1, 'healthcare': 1, 'ranges': 1, 'Chennai': 1, 'china': 1, 'drbalaramarjun': 1, 'alone': 1, 'sing': 1, 'strong': 1, 'FRCS': 1, 'Commonwealth': 1, 'MD': 1, 'k': 1, 'experience': 1, 'usually': 1, 'ENT': 1, 'purview': 1, 'Group': 1, 'highly': 1, 'trained': 1, 'apply': 1, 'employer': 1, 'standing': 1, 'takes': 1, 'visit': 1, 'doubt': 1, 'call': 1, 'type': 1, 'Lane': 1, 'share': 1, 'company': 1, 'Hardinge': 1, 'aware': 1, 'whatever': 1, 'CANNOT': 1, 'So': 1, 'adult': 1, 'Med': 1, 'cases': 1, 'town': 1, 'Peds': 1, 'completion': 1, 'setup': 1, 'overloaded': 1, 'Legend': 1, 'anywhere': 1, 'following': 1, 'making': 1, 'parkway': 1, 'history': 1, 'pushes': 1, 'tock': 1, 'insitution': 1, 'high': 1, 'something': 1, 'council': 1, 'tan': 1, 'syrups': 1, 'prolifc': 1, 'means': 1, 'write': 1, 'varies': 1, 'reattachement': 1, 'endorsement': 1, 'Don': 1, 'Human': 1, 'max': 1, 'applications': 1, 'designed': 1, 'such': 1, 'grop': 1, 'guys': 1, 'compulsory': 1, 'All': 1, 'maybe': 1, 'supervision': 1, 'things': 1, 'order': 1, 'Novenna': 1, 'prospective': 1, 'through': 1, 'looks': 1, 'Forces': 1, 'IRAS': 1, 'Full': 1, 'Emergency': 1, 'Schedule': 1, 'interesting': 1, 'surgeons': 1, 'accredited': 1, 'Director': 1, 'offers': 1, 'Moving': 1, 'conferment': 1, 'Estimate': 1, 'Tamil': 1, 'easier': 1, 'physicians': 1, 'Cardo': 1, 'Manpower': 1, 'ya': 1, 'docs': 1, 'regarding': 1, 'mention': 1, 'Senior': 1, 'yourself': 1, 'workload': 1, 'university': 1, 'courses': 1, 'APN': 1, 'graduated': 1, 'yeah': 1, 'consulation': 1, 'evens': 1, 'living': 1, 'medications': 1, 'prolly': 1, 'increase': 1, 'seriously': 1, 'Geriatrics': 1, 'health': 1, 'EAch': 1, 'got': 1, 'shows': 1, 'earns': 1, 'Renal': 1, 'G': 1, 'qualify': 1, 'complicated': 1, 'Firstly': 1, 'Security': 1, 'certified': 1, 'care': 1, 'advance': 1, 'training': 1, 'thread': 1, 'dunno': 1, 'National': 1, 'registrar': 1, 'IMGs': 1, 'NUS': 1, 'meet': 1, 'Please': 1, 'primary': 1, 'clear': 1, 'Indian': 1, 'carry': 1, 'force': 1, 'engineer': 1, 'anyone': 1, 'reference': 1, 'top': 1, 'Grant': 1, 'system': 1, 'plentiful': 1, 'clinical': 1, 'passed': 1, 'scheme': 1, 'nutrition': 1, 'stomach': 1, 'R': 1, 'focusing': 1, 'institution': 1, 'Auzzie': 1, 'grocery': 1, 'unfortunately': 1, 'sections': 1, 'submitted': 1, 'formely': 1, 'aesthetic': 1, 'merits': 1, 'taxis': 1, 'Nowadays': 1, 'Neonatology': 1, 'procedural': 1, 'comming': 1, 'Jurong': 1, 'Mumbai': 1, 'comfortable': 1, 'Epidural': 1, 'Gov': 1, 'Do': 1, 'Christian': 1, 'person': 1, 'efficient': 1, 'Graduates': 1, 'note': 1, 'without': 1, 'take': 1, 'Glenagles': 1, 'gmail': 1, 'Dr': 1, 'Nadu': 1, 'pain': 1, 'M': 1, 'most': 1, 'Chief': 1, 'amongst': 1, 'cap': 1, 'approved': 1, 'neurosurgery': 1, 'Google': 1, 'Work': 1, 'considered': 1, 'Armed': 1, 'average': 1, 'definitely': 1, 'posses': 1, 'typically': 1, 'auzzie': 1, 'sector': 1, 'walking': 1, 'show': 1, 'cheap': 1, 'Research': 1, 'certs': 1, 'find': 1, 'abotu': 1, 'We': 1, 'ratio': 1, 'jap': 1, 'Services': 1, 'Lasik': 1, 'Housing': 1, 'get': 1, 'rest': 1, 'probably': 1, 'during': 1, 'trade': 1, 'areas': 1, 'PHD': 1, 'Jawaharlal': 1, 'watever': 1, 'YES': 1, 'fledged': 1, 'set': 1, 'Seng': 1, 'see': 1, 'individual': 1, 'cardiothoratic': 1, 'fail': 1, 'close': 1, 'surgery': 1, 'John': 1, 'Officer': 1, 'subject': 1, 'said': 1, 'runs': 1, 'currently': 1, 'please': 1, 'below': 1, 'tend': 1, 'genius': 1, 'PG': 1, 'assistants': 1, 'Bangalore': 1, 'Cough': 1, 'email': 1, 'were': 1, 'His': 1, 'Inverventionalist': 1, 'approval': 1, 'ANy': 1, 'improve': 1, 'AND': 1, 'received': 1, 'C': 1, 'Resource': 1, 'equal': 1, 'consulations': 1, 'nephrology': 1, 'estates': 1, 'utilising': 1, 'goverment': 1, 'uni': 1, 'contribution': 1, 'suggest': 1, 'satisfaction': 1, 'active': 1, 'Here': 1, 'healthly': 1, 'roaring': 1, 'Cars': 1, 'been': 1, 'suburbs': 1, 'duties': 1, 'website': 1, 'else': 1, 'eatery': 1, 'minister': 1, 'apartement': 1, 'weeks': 1, 'standard': 1, 'Rajiv': 1, 'physician': 1, 'consultant': 1, 'engineering': 1, 'registerable': 1, 'while': 1, 'many': 1, 'hubs': 1, 'Level': 1, 'Building': 1, 'resident': 1, 'MRCS': 1, 'ie': 1, 'around': 1, 'different': 1, 'Oh': 1, 'bonus': 1, 'qualifications': 1, 'evil': 1, 'NOT': 1, 'student': 1, 'econs': 1, 'off': 1, 'center': 1, 'older': 1, 'charges': 1, 'Food': 1, 'savings': 1, 'trains': 1, 'savvy': 1, 'organization': 1, 'If': 1, 'Pondicherry': 1, 'stores': 1, 'Vellore': 1, 'just': 1, 'increasingly': 1, 'when': 1, 'obtain': 1, 'competitive': 1, 'MBBS': 1, 'oxford': 1, 'clinic': 1, 'BP': 1, 'questions': 1, 'n': 1, 'based': 1, 'now': 1, 'application': 1, 'had': 1, 'Changi': 1, 'internal': 1, 'parents': 1, 'careers': 1, 'MRCP': 1, 'tests': 1, 'hamemotology': 1, 'Unfortunately': 1, 'government': 1, 'Of': 1, 'couple': 1, 'sums': 1, 'possible': 1, 'inflation': 1, 'birth': 1, 'immediately': 1, 'amputed': 1, 'd': 1, 'admitted': 1, 'uproar': 1, 'popular': 1, 'works': 1, 'satisfactory': 1, 'clusters': 1, 'India': 1, 'conditional': 1, 'some': 1, 'authority': 1, 'X': 1, 'International': 1, 'transport': 1, 'Surgey': 1, 'scale': 1, 'However': 1, 'conditionally': 1, 'meds': 1, 'does': 1, 'officer': 1, 'says': 1, 'business': 1, 'Examplary': 1, 'equivalent': 1, 'graduates': 1, 'bachleor': 1, 'eye': 1, 'post': 1, 'simpler': 1, 'package': 1, 'newspapers': 1, 'months': 1, 'US': 1, 'attendings': 1, 'supervised': 1, 'Gandhi': 1, 'seeing': 1, 'own': 1, 'pays': 1, 'within': 1, 'Internal': 1, 'radiology': 1, 'there': 1, 'lol': 1, 'Every': 1, 'lot': 1, 'forward': 1, 'examination': 1, 'certificate': 1, 'form': 1, 'bus': 1, 'Doctors': 1, 'Well': 1, 'delivery': 1, 'Healthcare': 1, 'info': 1, 'esimates': 1, 'made': 1, 'applying': 1, 'happen': 1, 'attached': 1, 'problem': 1, 'supervisor': 1, 'inclusive': 1, 'nurses': 1, 'Some': 1, 'pie': 1, 'general': 1, 'To': 1, 'New': 1, 'accounting': 1, 'hospitals': 1, 'check': 1, 'fill': 1, 'no': 1, 'Postgraduate': 1, 'excel': 1, 'graduate': 1, 'Landed': 1, 'Besides': 1, 'test': 1, 'really': 1, 'Lady': 1, 'reportedly': 1, 'inquired': 1, 'students': 1, 'Drive': 1, 'helpful': 1, 'midnite': 1, 'St': 1, 'Rehabilitation': 1, 'practically': 1, 'As': 1, 'time': 1, 'overseas': 1})
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1167
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Fri Feb 15, 2013 8:38 pm

@metal Your python tutorial are like short notes, are awesome!
So here, as you quoted the code
I tried something on that line, but a little different. I also shortened the file a lot for everyone to try out different sorting ways.
This is what I tried.

Code: Select all
def indexer(lister): #lister is alist arg
    dicter={}
    for kk,v in enumerate(lister.split()):
        try:
            dicter[v]+=1
            print '%s is at index: ' %(v)+str(kk)
            print 'for word: %s - count: %d' % (v,dicter[v])
        except KeyError:
            dicter[v]=1
            print '%s is at index: ' %(v)+str(kk)
            print 'for word: %s - count: %d' % (v,dicter[v])
    return

Code: Select all
indexer(data)


O/P
indexer(data)
Firstly, is at index: 0
for word: Firstly, - count: 1
as is at index: 1
for word: as - count: 1
u is at index: 2
for word: u - count: 1
are is at index: 3
for word: are - count: 1
not is at index: 4
for word: not - count: 1
trained is at index: 5
for word: trained - count: 1
in is at index: 6
for word: in - count: 1
Singapore, is at index: 7
for word: Singapore, - count: 1
any is at index: 8
for word: any - count: 1
family is at index: 9
for word: family - count: 1
physician is at index: 10
for word: physician - count: 1
or is at index: 11
for word: or - count: 1
specialist is at index: 12
for word: specialist - count: 1
will is at index: 13
for word: will - count: 1
be is at index: 14
for word: be - count: 1
conditionally is at index: 15
for word: conditionally - count: 1
registered is at index: 16
for word: registered - count: 1
only.You is at index: 17
for word: only.You - count: 1
will is at index: 18
for word: will - count: 2
be is at index: 19
for word: be - count: 2
"supervised" is at index: 20
for word: "supervised" - count: 1
when is at index: 21
for word: when - count: 1
working is at index: 22
for word: working - count: 1
in is at index: 23
for word: in - count: 2
a is at index: 24
for word: a - count: 1
hospital. is at index: 25
for word: hospital. - count: 1
Full is at index: 26
for word: Full - count: 1
fledged is at index: 27
for word: fledged - count: 1
specialist is at index: 28
for word: specialist - count: 2
in is at index: 29
for word: in - count: 3
their is at index: 30
for word: their - count: 1
country is at index: 31
for word: country - count: 1
cannot is at index: 32
for word: cannot - count: 1
practice is at index: 33
for word: practice - count: 1
as is at index: 34
for word: as - count: 2
consultant is at index: 35
for word: consultant - count: 1
( is at index: 36
for word: ( - count: 1
or is at index: 37
for word: or - count: 2
attendings is at index: 38
for word: attendings - count: 1
). is at index: 39
for word: ). - count: 1
You is at index: 40
for word: You - count: 1
will is at index: 41
for word: will - count: 3
start is at index: 42
for word: start - count: 1
off is at index: 43
for word: off - count: 1
as is at index: 44
for word: as - count: 3
a is at index: 45
for word: a - count: 2
registrar is at index: 46
for word: registrar - count: 1
( is at index: 47
for word: ( - count: 2
or is at index: 48
for word: or - count: 3
resident) is at index: 49
for word: resident) - count: 1
Unfortunately, is at index: 50
for word: Unfortunately, - count: 1
you is at index: 51
for word: you - count: 1
cannot is at index: 52
for word: cannot - count: 2
immediately is at index: 53
for word: immediately - count: 1
setup is at index: 54
for word: setup - count: 1
a is at index: 55
for word: a - count: 3
private is at index: 56
for word: private - count: 1
practice. is at index: 57
for word: practice. - count: 1
And is at index: 58
for word: And - count: 1
yes, is at index: 59
for word: yes, - count: 1
suprise, is at index: 60
for word: suprise, - count: 1
suprise. is at index: 61
for word: suprise. - count: 1
I'm is at index: 62
for word: I'm - count: 1
not is at index: 63
for word: not - count: 2
a is at index: 64
for word: a - count: 4
doctor is at index: 65
for word: doctor - count: 1
. is at index: 66
for word: . - count: 1
I'm is at index: 67
for word: I'm - count: 2
an is at index: 68
for word: an - count: 1
engineer..Lol. is at index: 69
for word: engineer..Lol. - count: 1
Here is at index: 70
for word: Here - count: 1
are is at index: 71
for word: are - count: 2
those is at index: 72
for word: those - count: 1
Universities is at index: 73
for word: Universities - count: 1
: is at index: 74
for word: : - count: 1
All-India is at index: 75
for word: All-India - count: 1
Institute is at index: 76
for word: Institute - count: 1
of is at index: 77
for word: of - count: 1
Medical is at index: 78
for word: Medical - count: 1
Sciences is at index: 79
for word: Sciences - count: 1
Christian is at index: 80
for word: Christian - count: 1
Medical is at index: 81
for word: Medical - count: 2
College, is at index: 82
for word: College, - count: 1
Vellore is at index: 83
for word: Vellore - count: 1
Armed is at index: 84
for word: Armed - count: 1
Forces is at index: 85
for word: Forces - count: 1
Medical is at index: 86
for word: Medical - count: 3
College, is at index: 87
for word: College, - count: 2
Maharashtra is at index: 88
for word: Maharashtra - count: 1
University is at index: 89
for word: University - count: 1
of is at index: 90
for word: of - count: 2
Health is at index: 91
for word: Health - count: 1
Sciences is at index: 92
for word: Sciences - count: 2
Jawaharlal is at index: 93
for word: Jawaharlal - count: 1
Institute is at index: 94
for word: Institute - count: 2
of is at index: 95
for word: of - count: 3
Postgraduate is at index: 96
for word: Postgraduate - count: 1
Medical is at index: 97
for word: Medical - count: 4
Education is at index: 98
for word: Education - count: 1
& is at index: 99
for word: & - count: 1
Research, is at index: 100
for word: Research, - count: 1
Pondicherry is at index: 101
for word: Pondicherry - count: 1
University is at index: 102
for word: University - count: 2
Lady is at index: 103
for word: Lady - count: 1
Hardinge is at index: 104
for word: Hardinge - count: 1
Medical is at index: 105
for word: Medical - count: 5
College is at index: 106
for word: College - count: 1
(New is at index: 107
for word: (New - count: 1
Delhi), is at index: 108
for word: Delhi), - count: 1
University is at index: 109
for word: University - count: 3
of is at index: 110
for word: of - count: 4
Delhi is at index: 111
for word: Delhi - count: 1
Grant is at index: 112
for word: Grant - count: 1
Medical is at index: 113
for word: Medical - count: 6
College is at index: 114
for word: College - count: 2
(Mumbai), is at index: 115
for word: (Mumbai), - count: 1
Maharashtra is at index: 116
for word: Maharashtra - count: 2
University is at index: 117
for word: University - count: 4
of is at index: 118
for word: of - count: 5
Health is at index: 119
for word: Health - count: 2
Sciences is at index: 120
for word: Sciences - count: 3
St. is at index: 121
for word: St. - count: 1
John's is at index: 122
for word: John's - count: 1
Medical is at index: 123
for word: Medical - count: 7
College is at index: 124
for word: College - count: 3
(Bangalore), is at index: 125
for word: (Bangalore), - count: 1
Rajiv is at index: 126
for word: Rajiv - count: 1
Gandhi is at index: 127
for word: Gandhi - count: 1
University is at index: 128
for word: University - count: 5
of is at index: 129
for word: of - count: 6
Health is at index: 130
for word: Health - count: 3
Sciences is at index: 131
for word: Sciences - count: 4
Madras is at index: 132
for word: Madras - count: 1
Medical is at index: 133
for word: Medical - count: 8
College is at index: 134
for word: College - count: 4
(Chennai), is at index: 135
for word: (Chennai), - count: 1
Tamil is at index: 136
for word: Tamil - count: 1
Nadu is at index: 137
for word: Nadu - count: 1
Dr.M.G.R. is at index: 138
for word: Dr.M.G.R. - count: 1
Medical is at index: 139
for word: Medical - count: 9
University is at index: 140
for word: University - count: 6
The is at index: 141
for word: The - count: 1
rest is at index: 142
for word: rest - count: 1
must is at index: 143
for word: must - count: 1
contact is at index: 144
for word: contact - count: 1
the is at index: 145
for word: the - count: 1
Singapore is at index: 146
for word: Singapore - count: 1
Medical is at index: 147
for word: Medical - count: 10
council. is at index: 148
for word: council. - count: 1




metulburr wrote:
What I tried was counting the total no. of individual words, store them string by string in a dictionary

Yours looks overly complicated

This is a basic setup of what "i think" your looking for
Code: Select all
words = {}
f = open('test.txt')
data = f.read()

for word in data.split():
   try:
      words[word] += 1
   except KeyError:
      words[word] = 1
   
print(words)


The whole thing is based off f.read().split(), which splits the entire string of the text file into a list of words indexed by the space in the file. At that point if your want, you can strip off puncuation, etc.

The try/except is there because if you rearrange their statments, it will reassign whatevger value it "was" at to 1, losing the data, instead it first tries to add 1 to the value of that key, if the key doesnt exist, it gets a keyerror, at that point moves to the except and creates that key with value of one, so the next time around if it comes across that word, it increments it, and bypasses the except
Attachments
singapore.txt
Shortened same file singapore
(1.06 KiB) Downloaded 79 times
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Fri Feb 15, 2013 8:40 pm

@yoriz, this is a great forum for learning python. I am a newbie at this & im definitely gona try this out & learn new sorting methods. Remembering strings & print format specifications & their numerous functions is a lil wee bit tough at the start. still practicing.

Yoriz wrote:
Code: Select all
import re
from collections import Counter


def countWords(fileName):
    words = []
    with open(fileName, 'r') as readFile:
        for line in readFile:
            for word in re.findall(r'[A-Za-z]+', line):
                words.append(word)
    return Counter(words)

print countWords('singapore.txt')

Counter({'': 2578, 'a': 52, 'the': 50, 'to': 41, 'of': 38, 'in': 31, 'for': 25, 'about': 21, 'is': 20, 'K': 16, 'medical': 16, 'that': 15, 'are': 14, 'Medical': 14, 'you': 14, 'and': 13, 'as': 13, 'be': 11, 'or': 11, 'with': 11, 'private': 10, 'Singapore': 10, 'at': 10, 's': 9, 'registration': 9, 'all': 8, 'GP': 8, 'more': 8, 'not': 8, 'an': 8, 'it': 8, 'specialist': 7, 'from': 7, 'years': 7, 'The': 7, 'will': 7, 'up': 7, 'u': 7, 'here': 6, 'SMC': 6, 'hospital': 6, 'sg': 6, 'good': 6, 'University': 6, 'have': 6, 'who': 6, 'College': 6, 'on': 6, 'www': 6, 'i': 6, 'school': 5, 'few': 5, 'can': 5, 'how': 5, 'year': 5, 'qualification': 5, 'need': 5, 'GPs': 5, 'etc': 5, 'com': 5, 'like': 5, 'per': 5, 'Health': 4, 'this': 4, 'if': 4, 'so': 4, 'them': 4, 'Medicine': 4, 'I': 4, 'There': 4, 'any': 4, 'also': 4, 'which': 4, 'do': 4, 'country': 4, 'relevant': 4, 'basic': 4, 'has': 4, 'You': 4, 'It': 4, 'contact': 4, 'yes': 4, 'Ok': 4, 'Sciences': 4, 't': 4, 'mth': 4, 'income': 4, 'very': 3, 'list': 3, 'cost': 3, 'General': 3, 'typical': 3, 'over': 3, 'course': 3, 'MIT': 3, 'actually': 3, 'practice': 3, 'day': 3, 'practising': 3, 'out': 3, 'medicine': 3, 'gov': 3, 'million': 3, 'one': 3, 'postgraduate': 3, 'salary': 3, 'm': 3, 'local': 3, 'where': 3, 'For': 3, 'we': 3, 'simple': 3, 'dun': 3, 'recognised': 3, 'child': 3, 'And': 3, 'doctor': 3, 'practise': 3, 'employment': 3, 'by': 3, 'http': 3, 'was': 3, 'but': 3, 'compared': 3, 'under': 2, 'me': 2, 'surgeon': 2, 'smc': 2, 'small': 2, 'work': 2, 'what': 2, 'section': 2, 'public': 2, 'degree': 2, 'reported': 2, 'kids': 2, 'prior': 2, 'survey': 2, 'family': 2, 'ask': 2, 'licensing': 2, 'working': 2, 'criteria': 2, 'must': 2, 'car': 2, 'Pte': 2, 'address': 2, 'tax': 2, 'information': 2, 'place': 2, 'A': 2, 'may': 2, 'cannot': 2, 'before': 2, 'Delhi': 2, 'they': 2, 'possess': 2, 'In': 2, 'drop': 2, 'suprise': 2, 'Council': 2, 'shortage': 2, 'practitioner': 2, 'registrable': 2, 'raffles': 2, 'issue': 2, 'births': 2, 'quite': 2, 'Maharashtra': 2, 'isn': 2, 'first': 2, 'Universities': 2, 'nhg': 2, 'done': 2, 'directly': 2, 'Website': 2, 'practitioners': 2, 'singhealth': 2, 'least': 2, 'their': 2, 'too': 2, 'national': 2, 'listed': 2, 'B': 2, 'population': 2, 'depends': 2, 'patients': 2, 'Generally': 2, 'bring': 2, 'much': 2, 'should': 2, 'only': 2, 'ones': 2, 'earn': 2, 'bad': 2, 'she': 2, 'Education': 2, 'med': 2, 'Hospital': 2, 'best': 2, 'That': 2, 'sorta': 2, 'come': 2, 'annual': 2, 'lokun': 2, 'Ltd': 2, 'period': 2, 'Lol': 2, 'expensive': 2, 'due': 2, 'look': 2, 'these': 2, 'pay': 2, 'gets': 2, 'temporary': 2, 'singapore': 2, 'hand': 2, 'well': 2, 'OBGY': 2, 'world': 2, 'know': 2, 'google': 2, 'people': 2, 'back': 2, 'Institute': 2, 'schedule': 2, 'each': 2, 'would': 2, 'housemanship': 2, 'your': 2, 'question': 2, 'start': 2, 'pa': 2, 'complete': 2, 'offer': 2, 'registered': 2, 'he': 2, 'wish': 2, 'ur': 2, 'similar': 2, 'field': 2, 'other': 2, 'ago': 2, 'land': 2, 'EVERYONE': 1, 'evidence': 1, 'consider': 1, 'Madras': 1, 'Parents': 1, 'salaries': 1, 'GMTI': 1, 'whose': 1, 'Non': 1, 'attentive': 1, 'granting': 1, 'opthamolgist': 1, 'young': 1, 'opportunities': 1, 'chaps': 1, 'those': 1, 'Physician': 1, 'Zzzz': 1, 'definetly': 1, 'advised': 1, 'GI': 1, 'evaded': 1, 'applicable': 1, 'leave': 1, 'He': 1, 'its': 1, 'neighborhood': 1, 'ortho': 1, 'recruitment': 1, 'Blk': 1, 'registeration': 1, 'internship': 1, 'goes': 1, 'net': 1, 'full': 1, 'healthcare': 1, 'ranges': 1, 'Chennai': 1, 'china': 1, 'drbalaramarjun': 1, 'alone': 1, 'sing': 1, 'strong': 1, 'FRCS': 1, 'Commonwealth': 1, 'MD': 1, 'k': 1, 'experience': 1, 'usually': 1, 'ENT': 1, 'purview': 1, 'Group': 1, 'highly': 1, 'trained': 1, 'apply': 1, 'employer': 1, 'standing': 1, 'takes': 1, 'visit': 1, 'doubt': 1, 'call': 1, 'type': 1, 'Lane': 1, 'share': 1, 'company': 1, 'Hardinge': 1, 'aware': 1, 'whatever': 1, 'CANNOT': 1, 'So': 1, 'adult': 1, 'Med': 1, 'cases': 1, 'town': 1, 'Peds': 1, 'completion': 1, 'setup': 1, 'overloaded': 1, 'Legend': 1, 'anywhere': 1, 'following': 1, 'making': 1, 'parkway': 1, 'history': 1, 'pushes': 1, 'tock': 1, 'insitution': 1, 'high': 1, 'something': 1, 'council': 1, 'tan': 1, 'syrups': 1, 'prolifc': 1, 'means': 1, 'write': 1, 'varies': 1, 'reattachement': 1, 'endorsement': 1, 'Don': 1, 'Human': 1, 'max': 1, 'applications': 1, 'designed': 1, 'such': 1, 'grop': 1, 'guys': 1, 'compulsory': 1, 'All': 1, 'maybe': 1, 'supervision': 1, 'things': 1, 'order': 1, 'Novenna': 1, 'prospective': 1, 'through': 1, 'looks': 1, 'Forces': 1, 'IRAS': 1, 'Full': 1, 'Emergency': 1, 'Schedule': 1, 'interesting': 1, 'surgeons': 1, 'accredited': 1, 'Director': 1, 'offers': 1, 'Moving': 1, 'conferment': 1, 'Estimate': 1, 'Tamil': 1, 'easier': 1, 'physicians': 1, 'Cardo': 1, 'Manpower': 1, 'ya': 1, 'docs': 1, 'regarding': 1, 'mention': 1, 'Senior': 1, 'yourself': 1, 'workload': 1, 'university': 1, 'courses': 1, 'APN': 1, 'graduated': 1, 'yeah': 1, 'consulation': 1, 'evens': 1, 'living': 1, 'medications': 1, 'prolly': 1, 'increase': 1, 'seriously': 1, 'Geriatrics': 1, 'health': 1, 'EAch': 1, 'got': 1, 'shows': 1, 'earns': 1, 'Renal': 1, 'G': 1, 'qualify': 1, 'complicated': 1, 'Firstly': 1, 'Security': 1, 'certified': 1, 'care': 1, 'advance': 1, 'training': 1, 'thread': 1, 'dunno': 1, 'National': 1, 'registrar': 1, 'IMGs': 1, 'NUS': 1, 'meet': 1, 'Please': 1, 'primary': 1, 'clear': 1, 'Indian': 1, 'carry': 1, 'force': 1, 'engineer': 1, 'anyone': 1, 'reference': 1, 'top': 1, 'Grant': 1, 'system': 1, 'plentiful': 1, 'clinical': 1, 'passed': 1, 'scheme': 1, 'nutrition': 1, 'stomach': 1, 'R': 1, 'focusing': 1, 'institution': 1, 'Auzzie': 1, 'grocery': 1, 'unfortunately': 1, 'sections': 1, 'submitted': 1, 'formely': 1, 'aesthetic': 1, 'merits': 1, 'taxis': 1, 'Nowadays': 1, 'Neonatology': 1, 'procedural': 1, 'comming': 1, 'Jurong': 1, 'Mumbai': 1, 'comfortable': 1, 'Epidural': 1, 'Gov': 1, 'Do': 1, 'Christian': 1, 'person': 1, 'efficient': 1, 'Graduates': 1, 'note': 1, 'without': 1, 'take': 1, 'Glenagles': 1, 'gmail': 1, 'Dr': 1, 'Nadu': 1, 'pain': 1, 'M': 1, 'most': 1, 'Chief': 1, 'amongst': 1, 'cap': 1, 'approved': 1, 'neurosurgery': 1, 'Google': 1, 'Work': 1, 'considered': 1, 'Armed': 1, 'average': 1, 'definitely': 1, 'posses': 1, 'typically': 1, 'auzzie': 1, 'sector': 1, 'walking': 1, 'show': 1, 'cheap': 1, 'Research': 1, 'certs': 1, 'find': 1, 'abotu': 1, 'We': 1, 'ratio': 1, 'jap': 1, 'Services': 1, 'Lasik': 1, 'Housing': 1, 'get': 1, 'rest': 1, 'probably': 1, 'during': 1, 'trade': 1, 'areas': 1, 'PHD': 1, 'Jawaharlal': 1, 'watever': 1, 'YES': 1, 'fledged': 1, 'set': 1, 'Seng': 1, 'see': 1, 'individual': 1, 'cardiothoratic': 1, 'fail': 1, 'close': 1, 'surgery': 1, 'John': 1, 'Officer': 1, 'subject': 1, 'said': 1, 'runs': 1, 'currently': 1, 'please': 1, 'below': 1, 'tend': 1, 'genius': 1, 'PG': 1, 'assistants': 1, 'Bangalore': 1, 'Cough': 1, 'email': 1, 'were': 1, 'His': 1, 'Inverventionalist': 1, 'approval': 1, 'ANy': 1, 'improve': 1, 'AND': 1, 'received': 1, 'C': 1, 'Resource': 1, 'equal': 1, 'consulations': 1, 'nephrology': 1, 'estates': 1, 'utilising': 1, 'goverment': 1, 'uni': 1, 'contribution': 1, 'suggest': 1, 'satisfaction': 1, 'active': 1, 'Here': 1, 'healthly': 1, 'roaring': 1, 'Cars': 1, 'been': 1, 'suburbs': 1, 'duties': 1, 'website': 1, 'else': 1, 'eatery': 1, 'minister': 1, 'apartement': 1, 'weeks': 1, 'standard': 1, 'Rajiv': 1, 'physician': 1, 'consultant': 1, 'engineering': 1, 'registerable': 1, 'while': 1, 'many': 1, 'hubs': 1, 'Level': 1, 'Building': 1, 'resident': 1, 'MRCS': 1, 'ie': 1, 'around': 1, 'different': 1, 'Oh': 1, 'bonus': 1, 'qualifications': 1, 'evil': 1, 'NOT': 1, 'student': 1, 'econs': 1, 'off': 1, 'center': 1, 'older': 1, 'charges': 1, 'Food': 1, 'savings': 1, 'trains': 1, 'savvy': 1, 'organization': 1, 'If': 1, 'Pondicherry': 1, 'stores': 1, 'Vellore': 1, 'just': 1, 'increasingly': 1, 'when': 1, 'obtain': 1, 'competitive': 1, 'MBBS': 1, 'oxford': 1, 'clinic': 1, 'BP': 1, 'questions': 1, 'n': 1, 'based': 1, 'now': 1, 'application': 1, 'had': 1, 'Changi': 1, 'internal': 1, 'parents': 1, 'careers': 1, 'MRCP': 1, 'tests': 1, 'hamemotology': 1, 'Unfortunately': 1, 'government': 1, 'Of': 1, 'couple': 1, 'sums': 1, 'possible': 1, 'inflation': 1, 'birth': 1, 'immediately': 1, 'amputed': 1, 'd': 1, 'admitted': 1, 'uproar': 1, 'popular': 1, 'works': 1, 'satisfactory': 1, 'clusters': 1, 'India': 1, 'conditional': 1, 'some': 1, 'authority': 1, 'X': 1, 'International': 1, 'transport': 1, 'Surgey': 1, 'scale': 1, 'However': 1, 'conditionally': 1, 'meds': 1, 'does': 1, 'officer': 1, 'says': 1, 'business': 1, 'Examplary': 1, 'equivalent': 1, 'graduates': 1, 'bachleor': 1, 'eye': 1, 'post': 1, 'simpler': 1, 'package': 1, 'newspapers': 1, 'months': 1, 'US': 1, 'attendings': 1, 'supervised': 1, 'Gandhi': 1, 'seeing': 1, 'own': 1, 'pays': 1, 'within': 1, 'Internal': 1, 'radiology': 1, 'there': 1, 'lol': 1, 'Every': 1, 'lot': 1, 'forward': 1, 'examination': 1, 'certificate': 1, 'form': 1, 'bus': 1, 'Doctors': 1, 'Well': 1, 'delivery': 1, 'Healthcare': 1, 'info': 1, 'esimates': 1, 'made': 1, 'applying': 1, 'happen': 1, 'attached': 1, 'problem': 1, 'supervisor': 1, 'inclusive': 1, 'nurses': 1, 'Some': 1, 'pie': 1, 'general': 1, 'To': 1, 'New': 1, 'accounting': 1, 'hospitals': 1, 'check': 1, 'fill': 1, 'no': 1, 'Postgraduate': 1, 'excel': 1, 'graduate': 1, 'Landed': 1, 'Besides': 1, 'test': 1, 'really': 1, 'Lady': 1, 'reportedly': 1, 'inquired': 1, 'students': 1, 'Drive': 1, 'helpful': 1, 'midnite': 1, 'St': 1, 'Rehabilitation': 1, 'practically': 1, 'As': 1, 'time': 1, 'overseas': 1})
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm

Re: File Read Operation with counting each words in the file

Postby lovecodecakes » Fri Feb 15, 2013 8:42 pm

@metulburr its workin good. thanks!

metulburr wrote:there are other ways to do the same without the try/except way too.

you created a words dictionary & dictionaries can increment??

words is the dict, word is the key, which is each word in string (which will include the punctuation, etc.), and the value is an integer, which of course can increment, which is the count of each key (word) in the file
lovecodecakes
 
Posts: 56
Joined: Mon Feb 11, 2013 8:19 pm


Return to General Coding Help

Who is online

Users browsing this forum: Demontager, Google [Bot] and 3 guests