如何打印元组"RAW"



我知道我的代码一团糟,但我需要获得所需的赋值输出。我没有学到任何关于元组输出的知识,我的意思是如何操作。。。但我在互联网上发现的都是关于元组的,比如:(‘A’,10(有一个键和一个值。据我所知,我有一个有两个值的元组。

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)

我的输出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)

所需输出。。。

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

谢谢。

感谢@quamrana帮助我。。。这是给出的解决方案。。。

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])

原件:

print(tm)

解决方案(1(:

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

解决方案(2(:

print(*tm)

最新更新