On 31 August 2013 16:30, Chris Angelico <[email protected]> wrote:
>>
>> but doesn't solve all the cases (imagine a string or an iterator).
>
> Similar but maybe simpler, and copes with more arbitrary iterables:
>
> it=iter(range(5))
> print(next(it), end='')
> for i in it:
> print('',i, end='')
If you want to work with arbitrary iterables then you'll want
it = iter(iterable)
try:
val = next(it)
except StopIteration:
pass # Or raise or something?
else:
print(val, end='')
for i in it:
print('', i, end='')
Oscar
--
http://mail.python.org/mailman/listinfo/python-list