itertools suggestion
Magnus Lie Hetland
mlh at furu.idi.ntnu.no
Sat Feb 22 18:20:52 EST 2003
In article <mailman.1045939081.856.python-list at python.org>, Jimmy
Retzlaff wrote:
>Magnus Lie Hetland (mlh at furu.idi.ntnu.no) wrote:
>>Some things that might be useful (with rather arbitrary names)
>>
>> iatom(foo) -- an iterator that returns foo
>> iappend(it, foo) -- an iterator that exhausts it and then returns
>> foo
>>
>>The latter could, of course, be achieved with
>>
>> chain(it, iatom(foo))
>>
>>if chain is adopted. (Odd that it is documented but not included... :)
>...
>>Just a thought, though -- I'm sure there are other ways of doing this
>that
>>may be prettier...
>
>I would think [foo] would do as well as iatom(foo).
I suppose so -- except that that [foo] is just iterable -- not an
iterator (i.e. it doesn't have a next() method). So you'd have to use
iter([foo]). An alternative is, of course, to use times(foo, 1).
> If so, then I think
>chain(it, [foo]) would make iappend unnecessary.
Sure.
>Jimmy
--
Magnus Lie Hetland "Nothing shocks me. I'm a scientist."
http://hetland.org -- Indiana Jones
More information about the Python-list
mailing list