[Tutor] Dictionary Issue

Ltc Hotspot ltc.hotspot at gmail.com
Thu Aug 6 00:58:48 CEST 2015


Hi Mark,

Address identifies the email address with the maximum  number of sends:
cwen at iupui.edu.

Secondly, we are missing a count on the number of messages sent by
cwen at iupui.edu, i.e., 5.

Thirdly, maxval 'none' is not defined on line # 24

Questions: How do we define the value of none for the key maxval and
retrieve a number count on the number of messages sent by cwen at iupui.edu.


NameError:

Traceback (most recent call last)
C:\Users\vm\Desktop\apps\docs\Python\assignment_9_4_5.py in <module>()
     22 ## find the greatest number of mail messages.
     23
---> 24 maxval = none
     25 maxkee = none
     26 for kee, val in count.items():

NameError: name 'none' is not defined

In [52]: print address
cwen at iupui.edu

Revised data:


## The program looks for 'From ' lines and takes the second
## word of those lines as the person who sent the mail.

fname = raw_input("Enter file name: ")
handle = open (fname, 'r')
for line in handle:
    if line.startswith("From: "):
        address = line.split()[1]


## 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 address:
            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


#items are printed

print address

Regards,
Hal

>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list