How to print tuple "RAW"

Viewed 94

I know my code it's a mess, but I need to get the desired output for an assignment. I didn't learn anything about tuple output I mean how to manipulate... But all that I found on internet is about tuples like: ('A', 10) with a key and a value. And for what I understand I have a tuple with two values.

name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
raw_dat = list()
time = list()
hour = list()
dic = dict()
rdy = list()

for line in handle :
    if not line.startswith("From") : continue
    if line.startswith("From:") : continue
    raw_dat.append(line.split())

for item in raw_dat :
    item = item[5]
    time.append(item)

for data in time :
    hour.append(data[0:2])

for hr in hour:
    dic[hr] = dic.get(hr, 0) + 1
for tm in sorted(dic.items()) :
    print(tm)

My output atm...

('04', 3)
('06', 1)
('07', 1)
('09', 2)
('10', 3)
('11', 6)
('14', 1)
('15', 2)
('16', 4)
('17', 2)
('18', 1)
('19', 1)

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

Thank you.

1 Answers

Thank you @quamrana for helping me... This is the solution given...

name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
raw_dat = list()
time = list()
hour = list()
dic = dict()

for line in handle :
    if not line.startswith("From") : continue
    if line.startswith("From:") : continue
    raw_dat.append(line.split())

for item in raw_dat :
    item = item[5]
    time.append(item)

for data in time :
    hour.append(data[0:2])

for hr in hour:
    dic[hr] = dic.get(hr, 0) + 1
for tm in sorted(dic.items()) :
    print(tm[0], tm[1])

original :

print(tm)

solution (1) :

print(tm[0], tm[1])

solution (2) :

print(*tm)
Related