Skip to content

Instantly share code, notes, and snippets.

@yuba
Last active April 26, 2017 11:57
Show Gist options
  • Save yuba/856626cef96f5f572beec81046331d6b to your computer and use it in GitHub Desktop.
Save yuba/856626cef96f5f572beec81046331d6b to your computer and use it in GitHub Desktop.
sliceオブジェクトをインデックス番号のリストに変換する ref: http://qiita.com/yuba/items/245975ffc2f0322f8680
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