ltc.hotspot at gmail.com
Wed Aug 12 02:43:46 CEST 2015
I'm trying to write Python code to read through a data file and figure out
the distribution by hour of the dat for each message in the data file.
Python can pull the hour from the 'From ' line by finding the time and then
splitting the string a second time using a colon, i.e., From
stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008
Finally, accumulated the counts for each hour, print out the counts, sorted
by hour as shown below:
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
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
On Tue, Aug 11, 2015 at 5:26 PM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2015-08-12 01:01, Ltc Hotspot wrote:
>> Hi Everyone,
>> What is the list equivalent to line 12: ncount.sort(reverse=True)
>> 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)
>> print key,val
>> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list