counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
Hi Iam just starting out with python...My code below changes the txt file into a list and add them to an empty dictionary and print how often the word occurs, but it only seems to recognise and print the last entry of the txt file. Any help would be great. tm =open('ask.txt', 'r') dict = {} for

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Wednesday, December 19, 2012 11:55:28 PM UTC+13, Jussi Piitulainen wrote: > > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empty dictionary and print how > > > often the word occurs, but it only seems to recognise an

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:03:21 AM UTC+13, Steven D'Aprano wrote: > On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empt

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:21:57 AM UTC+13, Thomas Bach wrote: > Hi, > > > > just as a side-note > > > > On Wed, Dec 19, 2012 at 02:45:13AM -0800, : > > > for word in list: > > > if word in dict: > > > count = dict[word] > > >