Printing with interspersed element
Kirk Strauser
kirk at daycos.com
Thu Nov 6 11:42:13 EST 2008
At 2008-10-30T21:10:09Z, "Paulo J. Matos" <pocmatos at gmail.com> writes:
> Thanks for the tip but that has an issue when dealing with potentially
> millions of objects. You are creating a string in memory to then dump
> to a file [or screen] while you could dump to the file [or screen] as
> you go through the original string. Right?
How about:
def alternator(lst, sep):
for index, item in enumerate(lst):
if index:
yield sep
yield item
for item in alternator(list_of_objects, 10):
print item,
--
Kirk Strauser
The Day Companies
More information about the Python-list
mailing list