小编zz3*_*599的帖子

修改列表中的元组

我有这样的时间输入:

09:00 12:00
10:00 13:00
11:00 12:30
12:02 15:00
09:00 10:30
Run Code Online (Sandbox Code Playgroud)

我试图将其构建为元组列表,转换为分钟:

[(540, 720), (600, 780), (660, 750), (722, 900), (540, 630)]
Run Code Online (Sandbox Code Playgroud)

我想要一种更干净,更Pythonic的转换方式.我目前有一种笨拙的方式:

def readline(): 
    return sys.stdin.readline().strip().split()

natimes = [tuple(readline()) for _ in xrange(linesofinput))]
for i, (a,b) in enumerate(natimes):
    c = int(a.split(':')[0])* 60 + int(a.split(':')[1])
    d = int(b.split(':')[0])* 60 + int(b.split(':')[1])
    natimes[i] = (c,d)
Run Code Online (Sandbox Code Playgroud)

只是不觉得我在这里正确使用Python.

python python-2.7

2
推荐指数
1
解决办法
97
查看次数

标签 统计

python ×1

python-2.7 ×1