2012-06-21 59 views
0

由於該主題暗示我試圖從一個列表中獲取整數(以元組形式)並使用彈出功能將它們添加到另一個列表中Python - 從列表中拉出最小整數,然後「彈出」到另一個

這是我迄今爲止所做的,並且堅持這樣做。

loga = [(912, "Message A1") , (1000, "Message A2") , (988, "Message A3") , (1012, "Message A4") , (1002, "Message A5")] 

logb = [(926, "Message B1") , (1008, "Message B2") , (996, "Message B3") , (1019, "Message B4") , (1100, "Message B5")] 

logc = [(1056,"Message C1") , (1033, "Message C2") , (999, "Message C3") , (1054, "Message C4") , (1086, "Message C5")] 

logs = [loga, logb, logc] 

def find_lowest_i(logs): 
    for i in range(len(lst)): 
     log = lst(i) 

if len(log) > t = log[0][0] 

    if i==0 or t < lowest_t 
    lowest_i = i 
    lowest_t = t 

return i 

回答

1
loga = [(912, "Message A1") , (1000, "Message A2") , (988, "Message A3") , (1012, "Message A4") , (1002, "Message A5")] 

logb = [(926, "Message B1") , (1008, "Message B2") , (996, "Message B3") , (1019, "Message B4") , (1100, "Message B5")] 

logc = [(1056,"Message C1") , (1033, "Message C2") , (999, "Message C3") , (1054, "Message C4") , (1086, "Message C5")] 

logs = [loga, logb, logc] 
final=[] 
for log in logs: 
    for tup in log: 
     final.append(tup[0]) 
lowest_number=min(int(x) for x in final) 
return lowest_number 

這應該爲你做的伎倆,它的工作原理是通過logs目錄遍歷loga,logb,logc,追加數到final列表,然後使用與min()功能的列表中理解得到最低數。

相關問題