第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從二維列表中去除第一列?

如何從二維列表中去除第一列?

慕虎7371278 2023-06-06 17:30:20
嘗試從 2D 列表中刪除字符串,但僅在第一列中我的嘗試:list = [[x.strip('this') for x in y[0]] for y in list]示例列表:[["apple this","juice this"], ["orange this","lemonade this"], ["kiwi this","punch this"]]想要的結(jié)果:[["apple","juice this"], ["orange","lemonade this"], ["kiwi","punch this"]]只從第一列而不是第二列剝離“this”。最好甚至不檢查其他列。
查看完整描述

4 回答

?
慕尼黑8549860

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])


查看完整回答
反對 回復(fù) 2023-06-06
?
慕俠2389804

TA貢獻(xiàn)1719條經(jīng)驗 獲得超6個贊

嘗試這個

list = [[(x if i else x.strip()) for i,x in enumerate(y)] for y in list]


查看完整回答
反對 回復(fù) 2023-06-06
?
POPMUISE

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]



查看完整回答
反對 回復(fù) 2023-06-06
?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗 獲得超4個贊

你可以試試這個。這行代碼將刪除

[[i.replace(' this',''), j] for i, j in a]



查看完整回答
反對 回復(fù) 2023-06-06
  • 4 回答
  • 0 關(guān)注
  • 233 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號