My results look like this:
('04', 3)
('06', 1)
('07', 1)
('09', 2)
I want them to look like this:
04 3
06 1
07 1
09 2
I've tried split (Not a string, can't do that) .replace (requires string as left operand not a tuple.) I 'think' I've tried list comprehension correctly. I'm not clear what I should actually be doing to accomplish my desired end result. I'm trying to use n00b functions since I'm learning this therefore, I'm ignore Lambda as I have no clue what that is. I am trying to stick to list, dictionary, comprehension, slice etc at this point.
My example below won't run as written, I'm just trying to show my last attempt. When I comment out lines 15, 16, 17, it runs and creates the example shown above.
fname = input("Enter file:")
if len(fname) < 1 : fname = "mbox-short.txt"
emails = open(fname)
counts=dict()
for email in emails:
result=email.startswith('From ')
if result is True:
time=(email.split()[5])
hour=(time.split(':')[0])
counts[hour]=counts.get(hour, 0) +1
tmp=list()
for k, v in counts.items():
tmp.append( (k, v) )
tmp.sort()
for char in tmp:
if char in "(',)":
tmp.replace(char,'')
for k in tmp:
print (k)