AttributeError

Denis McMahon denismfmcmahon at gmail.com
Wed Aug 12 17:50:53 CEST 2015


On Tue, 11 Aug 2015 22:03:05 -0700, Ltc Hotspot wrote:

> Question: What sorted function should I write to produce the desired
> output, below:

Me, I'd start by declaring a dictionary to hold the data:

counts = { "{:02d}".format(h):0 for h in range(24) }

Then I'd parse the strings in the log file(s), incrementing counts[x] 
where x is the hour field of the timestamp.

Then I'd create a list of tuples:

ncounts = [(k,v) for k,v in counts.items()]

sort it by the hour field:

ncounts.sort(key = lambda x: x[0])

and print it:

for x in ncounts:
    print x[0], x1

-- 
Denis McMahon, denismfmcmahon at gmail.com


More information about the Python-list mailing list