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>It could be done with one <code>print</code> statement</p>

<pre><code>&gt;&gt;&gt; d = '123|china|jack|342|usa|Nick|324345|spin|Amy'
&gt;&gt;&gt; l = d.split('|')
&gt;&gt;&gt; print(*list(map(lambda v: ','.join(v),[l[x: x+3] for x in range(0, len(l), 3)])), sep='\n')
123,china,jack
342,usa,Nick
324345,spin,Amy
</code></pre>

<p>So now step by step</p>

<pre><code>&gt;&gt;&gt; d = '123|china|jack|342|usa|Nick|324345|spin|Amy'
&gt;&gt;&gt; l = d.split('|')  # splitting input string into list of str objects that separated with '|'
&gt;&gt;&gt; l
['123', 'china', 'jack', '342', 'usa', 'Nick', '324345', 'spin', 'Amy']
&gt;&gt;&gt; [l[x: x+3] for x in range(0, len(l), 3)]  # combining elements by 3
[['123', 'china', 'jack'], ['342', 'usa', 'Nick'], ['324345', 'spin', 'Amy']]
&gt;&gt;&gt; list(map(lambda v: ','.join(v),[l[x: x+3] for x in range(0, len(l), 3)]))  # merging every sublist to str with ',' as separator
['123,china,jack', '342,usa,Nick', '324345,spin,Amy']
&gt;&gt;&gt; print(*list(map(lambda v: ','.join(v),[l[x: x+3] for x in range(0, len(l), 3)])), sep='\n')  # final print
123,china,jack
342,usa,Nick
324345,spin,Amy
</code></pre>

python