Last active
April 26, 2017 11:57
-
-
Save yuba/856626cef96f5f572beec81046331d6b to your computer and use it in GitHub Desktop.
sliceオブジェクトをインデックス番号のリストに変換する ref: http://qiita.com/yuba/items/245975ffc2f0322f8680
This file contains 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
def iterate_by_slice(s: slice, length: int): | |
i, stop, step = s.indices(length) | |
if step > 0 : | |
while i < stop: | |
yield i | |
i += step | |
else: | |
while i > stop: | |
yield i | |
i += step |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment