close
[python]怎麼複製 itertools to list copy itertools
在使用groupby的時候,
發現同一個for內,操作過的itertools就不見了。
本來使用
new=old 的方式複製
才知道原來他是指到同一個id
所以,
使用new=old[:]
把 舊的list內容複製到new
但是上面作法僅限於list操作。

那對 itertools 呢?
使用,
下面的old是itertools.grouper
import itertools
new, old = itertools.tee(old)
就得到一個item相同的itertools.grouper 物件了。
這樣就可以對他進行list()操作或是set了。


python - how itertools.tee works, can type 'itertools.tee' be duplicated in order to save it's "status"? - Stack Overflow
http://stackoverflow.com/questions/3957270/how-itertools-tee-works-can-type-itertools-tee-be-duplicated-in-order-to-save
用python解决 Google Treasure Hunt 2008 Question:Primes - prettyinsight的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/prettyinsight/article/details/5038040


arrow
arrow
    文章標籤
    python itertools copy 複製
    全站熱搜

    peicheng 發表在 痞客邦 留言(0) 人氣()