String Splitter Brain Teaser
Bill Mill
bill.mill at gmail.com
Mon Mar 28 14:06:55 EST 2005
<snip everything>
> That is clearer. At this point, though, you don't need the enumerator any more
> (so you can avoid indexing each item):
Good point.
>
> def xgen(s):
> srciter = iter(s)
> item = [srciter.next()]
> for i in srciter:
> if i == '/':
> item.append(srciter.next())
> else:
> yield item
> item = [i]
> yield item
>
For some reason, keeping the != first feels a lot more logical to me,
but I think that's just a reflection of my particular mental model of
the problem. Also, item is a much clearer name than stack; I chose
stack just to point out how similar the solution to objection 2 was to
yours.
Peace
Bill Mill
bill.mill at gmail.com
More information about the Python-list
mailing list