HTH<br>
<br>
wat i ment is like i have<br>
<br>
x = [1, 2, 3, 4, 5]<br>
y = [2, 3, 4, 5, 1]<br>
<br>
and i want x and y as a string<br>
<br>
and i want to write it to a file so its like<br>
<br>
1 2 3 4 5<br>
2 3 4 5 1<br>
<br>
sorry about that misunderstanding<br><br><div><span class="gmail_quote">On 8/25/06, <b class="gmail_sendername">John Fouhy</b> &lt;<a href="mailto:john@fouhy.net">john@fouhy.net</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 26/08/06, Amadeo Bellotti &lt;<a href="mailto:amadeo.bellotti@gmail.com">amadeo.bellotti@gmail.com</a>&gt; wrote:<br>&gt; I need to convert a list of intgers to a string so for example<br>&gt;<br>&gt;&nbsp;&nbsp;I have this<br>&gt;&nbsp;&nbsp;x = [1, 2, 3, 4, 5, 6]
<br>&gt;<br>&gt;&nbsp;&nbsp;I want this<br>&gt;<br>&gt;&nbsp;&nbsp;x = &quot;1 2 3 4 5 6&quot;<br><br>Actually, I disagree with David's solution somewhat --- I think that<br>the pythonic way to do this is as follows:<br><br>Firstly, you can use a list comprehension to convert each integer into
<br>a separate string.&nbsp;&nbsp;If you don't know about list comprehensions, you<br>can read about them in any python tutorial.<br><br>&gt;&gt;&gt; x = [1, 2, 3, 4, 5]<br>&gt;&gt;&gt; y = [str(i) for i in x]<br>&gt;&gt;&gt; y<br>
['1', '2', '3', '4', '5']<br><br>Then you can use the .join() method of strings to join them into a<br>single line.&nbsp;&nbsp;In this case, the separator is a space, ' ':<br><br>&gt;&gt;&gt; z = ' '.join(y)<br>&gt;&gt;&gt; z<br>'1 2 3 4 5'
<br><br>If you want to put one number on each row, you can use the newline<br>character '\n' as a separator instead:<br><br>&gt;&gt;&gt; '\n'.join(y)<br>'1\n2\n3\n4\n5'<br>&gt;&gt;&gt; print '\n'.join(y)<br>1<br>2<br>3<br>
4<br>5<br><br>HTH!<br><br>--<br>John.<br></blockquote></div><br>