> -----Original Message----- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Mark Lawrence > Sent: Wednesday, August 05, 2015 3:23 PM > To: tutor@python.org > Subject: Re: [Tutor] Dictionary Issue > > On 05/08/2015 15:15, Ltc Hotspot wrote: > > Hi everyone: > > > > I want to write a python program that reads through the data file of > > mbox-short.txt.Mbox-short.txt, i.e., download is available at > > http://www.py4inf.com/code/mbox-short.txt. > > > > Secondly, I want for python to figure out who sent the greatest number > > of mail messages. > > > > The output should read: c...@iupui.edu 5 > > > > However, there is a traceback message: > > > > In [40]: %run 9_4_4.py > > File "C:\Users\vm\Desktop\apps\docs\Python\_9_4_4.py", line 19 > > count = dict() > > ^ > > SyntaxError: invalid syntax > > > > Raw data code reads: > > > > fname = raw_input("Enter file name: ") handle = open (fname, 'r') text > > = handle.read() > > > > ## The program looks for 'From ' lines and takes the second ## word of > > those lines as the person who sent the mail. > > > > addresses = set() > > for addr in [ text.split()[2]('From ') > > if fromline > > > > ## The program creates a Python dictionary that maps ## the sender's > > mail address to a count of the number ## of times they appear in the > > file. > > > > count = dict() > > for wrd in word: > > count[wrd]= count.get(wrd,0) +1 > > > > ## After the dictionary is produced, the program reads ## through the > > dictionary using a maximum loop to ## find the greatest number of mail > > messages. > > > > maxval = none > > maxkee = none > > for kee, val in count.items(): > > if maxval == none or maxval <val: > > maxval = val > > maxkee = kee > > > > print items > > > > Question: What is the cause of the dictionary line message? > > > > Learning to find these syntax errors is a skill you must learn for yourself. Very > often the error occurs one or even more lines before the line on which the > error is actually detected. So please go back from where the error is actually > reported and see what you can find. Very strong hint, do not ask again until > you've fixed at least two of the three errors, and there may be more :) >
It looks like the problem is with count=dict() Should be count=dict{} I may be wrong - U'm still a neophyte. crk _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor