例如,您有一系列患者的出入日期(进入,退出)像[(1,3),(2,5),(4,8),(9,10),(5,6),(4,7),(7,10)]和我想分开元素..救救我!
使用Python zip和Unzip概念,我们可以轻松地将其分开。例如:
a= [(1,3),(2,5),(4,8),(9,10),(5,6),(4,7),(7,10)]
b=[]
for start_d, end_d in a:
max_d = end_d - start_d
b.append(max_d)
print(f'Duration of stays max_d: {max_d}')
b.sort()
print(b)
print(b[(b.__len__()-1)])
和输出
Duration of stays max_d: 2
Duration of stays max_d: 3
Duration of stays max_d: 4
Duration of stays max_d: 1
Duration of stays max_d: 1
Duration of stays max_d: 3
Duration of stays max_d: 3
[1, 1, 2, 3, 3, 3, 4]
4// max-m day stay