首页 > 解决方案 > 将列表输入转换为字符串输出

问题描述

我有一个如下列表,我可以知道如何转换为字符串输出吗?

Input
A = [['I', 'love', 'apple','.'], 
     ['Today', 'is', 'Sunday', '.'], 
     ['How', 'are', 'you'],
     ['What', 'are', 'you','doing']]

Output
I love apple.
Today is Sunday.
How are you
What are you doing

标签: pythonlist

解决方案


您可以简单地使用for循环遍历嵌套在 list 中的每个列表A

A = [
    ['I', 'love', 'apple.'],
    ['Today', 'is', 'Sunday.'],
    ['How', 'are', 'you'],
    ['What', 'are', 'you', 'doing']
]

for row in A:
    print(' '.join(row))

推荐阅读