writing list contents to a file
Erik Max Francis
max at alcyone.com
Fri Dec 13 06:23:39 EST 2002
Christoph Lehmann wrote:
> Hi I am a newbie:
> I have two lists each with the same length: i want to write its
> content
> in the way
>
> list1Item1 list2Item1
> list1Item2 list2Item2
> ....
> list1Itemn list2Itemn
>
> what's the moste elegant way?
If the lists aren't too large, something like
for x, y in zip(L1, L2):
f.write("%s\t%s\n" % (x, y))
If they're potentially truly huge lists, then you'll probably want
something like
size = min(len(L1), len(L2)) # however you want to handle this
for i in xrange(size):
x, y = L1[i], L2[i]
f.write("%s\t%s\n" % (x, y))
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Together we can take this one day at a time
\__/ Sweetbox
Polly Wanna Cracka? / http://www.pollywannacracka.com/
The Internet resource for interracial relationships.
More information about the Python-list
mailing list