alan.gauld at btinternet.com
Wed Aug 12 02:45:08 CEST 2015
On 12/08/15 00:24, Ltc Hotspot wrote:
> Why is there an AttributeError, line 12, below : 'tuple' object has no
> attribute 'sort'?
Having answered that in my last email I just
noticed another problem...
> count = dict()
> fname = raw_input("Enter file name: ")#
> handle = open (fname, 'r')#
> for line in handle:
> if line.startswith("From "):
> address = line.split()
> line = line.rstrip()
> count[address] = count.get(address, 0) + 1
> for key,val in count.items():
> ncount = (key,val)
You are trying to sort a tuple that contains
a single key,value pair. The key is an IP address
represented as a string and the value is an integer.
How do you expect those two values to sort?
Hint: Try it at the >>> prompt.
> print key,val
And having attempted to sort them you do nothing
with the result.
What are you trying to do with the sort?
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor