我有一个字符串列表列表,我想将其转换为字符串列表,在每个列表项目之间添加一个空格。例如。将字符串列表转换为字符串列表
original_list = [['the', 'cat', 'in', 'the', 'hat'], ['fat', 'cat', 'sat', 'on', 'the', 'mat']]
desired_output = ['the cat in the hat', 'fat cat sat on the mat']
我知道我可以用这个做到这一点:
desired_output
for each in original_list:
desired_output.append(' '.join(each))
,但因为我有大量数据的工作我的理想寻找一种更有效的方式来做到这一点。
它应该是'''.join(each)'而不是'''.join(each)'代码 –
@KaushikNP Cheers - 这是一个错字。 – jdoe