NEWB: General purpose list iteration?
Donald Newcomb
DRNewcomb at attglobal.NOT.net
Fri Aug 12 18:33:20 EDT 2005
"Peter Otten" <__peter__ at web.de> wrote in message
news:ddhh60$d8s$00$1 at news.t-online.com...
> A non-recursive approach:
>
> def enumerate_ex(items):
> stack = [(enumerate(items), items)]
> while stack:
> en, seq = stack[-1]
> for index, item in en:
> if isinstance(item, list):
> stack.append((enumerate(item), item))
> break
> yield index, seq[index], seq
> else:
> stack.pop()
It's going to take me a while to figure out exactly what that does but it
sure does what I wanted it to.
Thanks.
--
Donald Newcomb
DRNewcomb (at) attglobal (dot) net
More information about the Python-list
mailing list