Last active
March 18, 2017 02:51
-
-
Save ksomemo/47696bc73bb82d5e4432 to your computer and use it in GitHub Desktop.
iteratorと参照を活かしたリストの分割 ref: http://qiita.com/ksomemo/items/7b0016e1758ac10bf61a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zip(*[iter(s)]*n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[iter([1,2,3])]*4 | |
# [<list_iterator at 0x103fb7048>, | |
# <list_iterator at 0x103fb7048>, | |
# <list_iterator at 0x103fb7048>, | |
# <list_iterator at 0x103fb7048>] | |
zip(*[iter([1,2,3])]*4) | |
# => zip(0x103fb7048, 0x103fb7048, 0x103fb7048, 0x103fb7048) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iteratorと参照を活かしたリストの分割
zipのdocumentに書いてあった
http://docs.python.jp/3.4/library/functions.html?highlight=zip#zip
iter
iteratorオブジェクトに包んで、iterateするごとに要素を返すようにする
zip
pythonのzipは可変長引数なので、3つ以上でも問題ない
iterとzip