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

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

如何從數(shù)組中的字符串中刪除 \n

如何從數(shù)組中的字符串中刪除 \n

一只萌萌小番薯 2021-07-20 17:05:19
代碼如下所示:import stddrawimport sysimport stdio#open the lexicon filelexicon_input_file = open(sys.argv[1])# copy the lexicon over from filelexicon = lexicon_input_file.readlines()#close the lexicon filelexicon_input_file.close()for i in range(len(lexicon)): #4000 words    # breaks down entire lexicon into each element incremented from 0,1,2,3,4,..    line_of_text = lexicon[i]    line_without_newline = line_of_text.rstrip('\n')print(lexicon)終端結(jié)果如下所示:['the\n', 'be\n', 'and\n', 'of\n', 'a\n', 'in\n', 'to\n', 'have\n', 'it\n'.......我如何從元素的末端擺脫 \n。我試過 rsplit 但不知道為什么它不起作用。我對編碼真的很陌生!
查看完整描述

2 回答

?
慕碼人8056858

TA貢獻1803條經(jīng)驗 獲得超6個贊

這應(yīng)該刪除 '\n':

lexicon = [i.strip('\n') for i in lexicon]
print(lexicon)


查看完整回答
反對 回復(fù) 2021-07-28
  • 2 回答
  • 0 關(guān)注
  • 341 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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