我如何在这样的数组中分隔值。[[(1,3),(2,5),(4,8),(9,10),(5,6),( 4,7),(7,10)]?

问题描述 投票:-1回答:1

例如,您有一系列患者的出入日期(进入,退出)像[(1,3),(2,5),(4,8),(9,10),(5,6),(4,7),(7,10)]和我想分开元素..救救我!

java arrays data-structures collections key-value
1个回答
0
投票

使用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
© www.soinside.com 2019 - 2024. All rights reserved.