4 回答

TA貢獻(xiàn)1818條經(jīng)驗 獲得超11個贊
使用split()和zip():
ee = [["apple this","juice this"],
["orange this","lemonade this"],
["kiwi this","punch this"]]
splitted = [x[0].split()[0] for x in ee] # ['apple', 'orange', 'kiwi']
later_lst = [x[1] for x in ee] # ['juice this', 'lemonade this', 'punch this']
print([list(l) for l in zip(splitted, later_lst)])
輸出:
[['apple', 'juice this'], ['orange', 'lemonade this'], ['kiwi', 'punch this']]
單線:
print([list(l) for l in zip([x[0].split()[0] for x in ee], [x[1] for x in ee])])
編輯:
較短的版本:
print([[x[0].split()[0], x[1]] for x in ee])

TA貢獻(xiàn)1719條經(jīng)驗 獲得超6個贊
嘗試這個
list = [[(x if i else x.strip()) for i,x in enumerate(y)] for y in list]

TA貢獻(xiàn)1765條經(jīng)驗 獲得超5個贊
您可以使用
list = [[x.strip('strip this') if j==0 else x for j,x in enumerate(y)] for y in list]
添加回答
舉報