我嘗試使用列表理解做以下操作:雙for循環列表理解
Input: [['hello ', 'world '],['foo ',' bar']]
Output: [['hello', 'world'], ['foo', 'bar']]
這裏是一個如何做沒有列表解析:
a = [['hello ', 'world '],['foo ',' bar']]
b = []
for i in a:
temp = []
for j in i:
temp.append(j.strip())
b.append(temp)
print(b)
#[['hello', 'world'], ['foo', 'bar']]
我怎樣才能做到這一點使用列表解析?
我會接受這個,因爲這是第一個答案。謝謝。 – Sait