Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个切片对象
s = slice(a,b,c)
和一个数组长度n,是否有一个很好的现成的元素迭代器,这样我就可以做类似的事情:
n
for index in FUNCTION_I_WANT(s, n): do_whatever(index)
并让它表现得像列表切片,超越真正可怕的:
def HACKY_VERSION_OF_FUNCTION_I_WANT(s,n): yield range(n).__getitem__(s)
def FUNCTION_I_WANT(s, n): return range(*s.indices(n))