擅长:python、mysql、java
<p>或者,您可以使用<code>pandas</code>,它肯定可以处理不同的行长度,例如:</p>
<pre><code>import pandas as pd
data = [('01', ['name abc', 'age 32', 'address addr123']),
('02', ['name def', 'age 22'])] # example of a shorter row
df = pd.DataFrame.from_dict({i:{a.split()[0]:a.split()[1] for a in j} for i,j in data},
orient='index')
df.to_csv('filename.csv')
</code></pre>
<p>编辑:假设你的值中没有空格</p>
<pre><code>('01', ['name ghi jkl', 'age 42', 'address addr123'])
</code></pre>
<p>但我认为目前所有的答案都是这样。你知道吗</p>