我試圖從我擁有的列表中刪除引號。我有這個:Letcodea = ['F', 'G', 'L', 'Q', 'P', 'F', 'G', 'L', 'Q', 'P', 'F', 'G', 'L', 'Q', 'P', 'F', 'G', 'L', 'Q', 'P']他們使用一個簡單的代碼我有這個:gamma = [] omega = [','.join(map(repr, letcodea))] for oem in omega: oem = oem.replace("'", "") gamma.append(oem) gamma ['F,G,L,Q,P,F,G,L,Q,P,F,G,L,Q,P,F,G,L,Q,P']有誰知道我可以刪除列表開頭和結尾處的引號嗎?先感謝您
1 回答

RISEBY
TA貢獻1856條經驗 獲得超5個贊
我想你只是想要:
print('[' + ','.join(Letcodea) + ']')
或者如果您確實想使用所有額外的代碼:
gamma = []
omega = [','.join(map(repr, Letcodea))]
for oem in omega:
oem = oem.replace("'", "")
gamma.append(oem)
print('[' + gamma[0] + ']')
無論哪種方式,您都會得到:
[F,G,L,Q,P,F,G,L,Q,P,F,G,L,Q,P,F,G,L,Q,P]
添加回答
舉報
0/150
提交
取消