[Tutor] Dictionary Issue

Alan Gauld alan.gauld at btinternet.com
Fri Aug 7 23:20:10 CEST 2015


On 07/08/15 19:18, Ltc Hotspot wrote:

> I want to find the max val ,  keys and values are defined on line 10:
> for kee, val in count.items():

Yes we know that, but you are not answering the questions we pose. 
Instead you seem to post random changes to your code and ask new 
questions which makes it hard to know whether you understand what is 
going on and to guide you to a solution.

> Then,  maxval determines the max value on line 11:
> if val > maxval:
>
> right, view a copy of the revised code at
> http://tinyurl.com/nvzdw8k

OK, You have only posted partial code because you don't have
the part where you read the filename etc. But assuming it
has not changed then the new code looks correct - almost.

Your assignment said NOT to use the lines starting From: (with
colon :) But your code tests for startswith('From: ') so you
are doing what you were told not to do.

If you remove the colon from the end of From (but keep the space)
it should be correct.

> Question1: are these assumptions true, above?

Yes, pretty much correct.

> Question2: dict maps strings into keys and values?

Not quite. A dictionary has a key and a corresponding value.
The key can be ANY immutable (unchangeable) object - string,
integer, tuple, etc.
The value can be any Python object.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list