python to split a long string into different rows
<p><code>123|china|jack|342|usa|Nick|324345|spin|Amy</code></p>

<p>I want the end result like this(I know I need a new line for every 3 element):</p>

<pre><code>123,china,jack
342,usa,Nick
324345,spin,Amy
</code></pre>

<p>Thank you</p>

<p>Try that:</p>

<pre><code>x = '123|china|jack|342|usa|Nick|324345|spin|Amy'

l = x.split('|')
new_l = [l[i:i+3] for i in range(0,len(l),3)]
</code></pre>

<p>This will give you:</p>

<pre><code>&gt;&gt;&gt; for i in new_l:
...     print ','.join(i)
...
123,china,jack
342,usa,Nick
324345,spin,Amy
</code></pre>

<blockquote>
  <p>Update: to read the file</p>
</blockquote>

<p>To read the file as string do the following:</p>

<pre><code>with open('your_file.txt', 'r') as myfile:
    x=myfile.read().replace('\n', '|')
</code></pre>

python