小编Kir*_*ill的帖子

Python遍历列表列表

我有列表列表,我需要通过 Python 遍历每个字符串,删除空格(条)并将列表保存到新列表中。

例如原始列表: org = [ [' a ','b '],['c ',' d '],['e ',' f'] ]

期待新列表: new = [ ['a','b'],['c','d'],['e','f'] ]

我从下面的代码开始,但不知道如何将剥离的对象添加到新的列表列表中。new.append(item) - 创建没有内部列表的简单列表。

new = [] for items in org: for item in items: item= item.strip() new.append(item)

python python-3.x

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

python-3.x ×1