AttributeError
Ltc Hotspot
ltc.hotspot at gmail.com
Wed Aug 12 01:03:05 EDT 2015
Message heard loud and clear:
There are no error messages, the output is the issue.
Question: What sorted function should I write to produce the desired
output, below:
Desired output:
04 3
06 1
07 1
09 2
10 3
11 6
14 1
15 2
16 4
17 2
18 1
19 1
Latest revised code:
count = dict()
fname = raw_input("Enter file name: ")#
handle = open (fname, 'r')#
for line in handle:
if line.startswith("From "):
address = line.split()[5]
line = line.rstrip()
count[address] = count.get(address, 0) + 1
lst = list()
for key,val in count.items():
lst.append( (val, key) )
lst.sort(reverse=True)
for val, key in lst[:12]:
print key,val
Output code:
In [3]: %run assignment_10_2_v_01
Enter file name: mbox-short.txt
16:23:48 1
16:23:48 1
11:11:52 1
17:07:00 1
16:23:48 1
11:11:52 1
17:07:00 1
16:23:48 1
11:11:52 1
04:07:34 1
17:07:00 1
16:23:48 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
04:07:34 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
04:07:34 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
In [4]:
Regards,
Hal
> >
> >
> > Error message, reads: AttributeError, line 12, below : 'tuple'
> > object has no attribute 'sort'
> >
> > Raw data code, available at http://tinyurl.com/ob89r9p
> > Embedded data code, available at http://tinyurl.com/qhm4ppq
> > Visualization URL link, available at http://tinyurl.com/ozzmffy
> >
> > What are you trying to do? Why are you trying to sort a key/value
> > pair in reverse order?
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> >
More information about the Python-list
mailing list