我有一个清单清单。如何在包含逗号和引号的列表内拆分字符串,然后将其转换为字符串:
列表结构如下:
test_list = [['00000','test', 26.84, 67.8, 14.7, 3.2143838377847933, 'Test 39-64, bot, 8.625" AS', 'NORMAL', 'Wave', 'D'], ['00001','test', 26.84, 67.8, 14.7, 3.2143838377847933, 'Test 39-64, bot, 8.625" AS', 'NORMAL', 'Wave', 'D']]
我当前的实现为我提供了以下内容:
'00000,test, 26.84, 67.8, 14.7, 3.2143838377847933, Test 39-64, bot, 8.625" AS, NORMAL, Wave, D'
基于以下代码:
tests = '\n'.join(','.join(map(str, row)) for row in test_list)
如果可能,我希望我的期望结果如下所示:
' 00000,test, 26.84, 67.8, 14.7, 3.2143838377847933, 'Test 39-64, bot, 8.625" AS, NORMAL', Wave, D
我不确定如何实现这一目标
答案 0 :(得分:1)
如果我了解得很好,则可以选择以下方法:
l = [['00000','test', 26.84, 67.8, 14.7, 3.2143838377847933, 'Test 39-64, bot, 8.625" AS', 'NORMAL', 'Wave', 'D'], ['00001','test', 26.84, 67.8, 14.7, 3.2143838377847933, 'Test 39-64, bot, 8.625" AS', 'NORMAL', 'Wave', 'D']]
for x in l:
result = ''
for y in x:
result += f'"{y}", '
result = result[:-2]
print(result)