2017-10-21 37 views
0

我有迭代器叫做「最後」的名單之前,每個迭代持有5個值:迭代器的列表,需要通過每個迭代完全在移動到下一個

last = 
[<itertools.islice at 0x10bd29940>, 
<itertools.islice at 0x10cc914c8>, 
<itertools.islice at 0x10b94f7e0>] 

每個系列指數(下面)也包含5個日期,我想在完成下一個迭代之前遍歷「last」中的每個迭代器。 (每個series.index,經過5次,那麼當它5次移動通過下一迭代下一series.index,循環等

到目前爲止,我已經試過;

for date in series.index: 
    net = (next(last) - 100)/100 

for date in series.index: 
    net = ([next(n) for n in last] - 100)/100 

不知道如何解決這個問題(?是有什麼在itertools)

+0

嘗試使用'itertools.chain.from_iterable'鏈接迭代器' –

+0

'爲它在最後:for x in it ...'? –

+0

你究竟想在這裏完成什麼?什麼是「下一個」系列索引 - 系列索引是什麼? –

回答

0

沒有數據,預期輸出,它很難猜測

但繼承人一試:(zip是在迭代器「平行」的操作非常有用)

last = [range(1000,6000,1000), range(2000,7000,1000), range(3000,8000,1000)] 

series =[range(1,6,1), range(2,7,1), range(3,8,1)] 

[[*zip(srs, map(lambda x: (x - 100)/100, ls))] for srs, ls in zip(series, last)] 

[[(1, 9.0), (2, 19.0), (3, 29.0), (4, 39.0), (5, 49.0)], 
[(2, 19.0), (3, 29.0), (4, 39.0), (5, 49.0), (6, 59.0)], 
[(3, 29.0), (4, 39.0), (5, 49.0), (6, 59.0), (7, 69.0)]]