3 回答

TA貢獻1772條經(jīng)驗 獲得超8個贊
123 | ' '.join(' input a ,b,c,d;'.split()[ 1 :]) # 'a,b,c,d;' |
其實這種問題,你也可以完全使用。
1 | 'input a ,b,c,d;' .raplace( 'input' , ' ').replace(' output ', ' ') |
這種去替換
但是你描述的還是不是太清楚
或者你可以將第一個元素選擇出來,然后再替換
123 | 'input a ,b,c,d;' .replace( 'input a ,b,c,d;' .split()[ 0 ], '') # 結(jié)果: ' a ,b,c,d;' |

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

TA貢獻1757條經(jīng)驗 獲得超8個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import re
f = open('word.txt','r') word = f.read() f.close()
# ------- 1 ------- wList1 = [] word1 = word.split(',') for i in word1: wList1.append(i.lower()) wLen1 = len(wList1) print 'number of word:', wLen1, '\n', wList1
# ------- 2 ------- wList2 = [] word2 = re.findall('[a-zA-Z]+', word) for i in word2: wList2.append(i.lower()) wLen2 = len(wList2) print '\nnumber of word:', wLen2, '\n', wList2 |
兩種方法做的,如果單詞之間的符號都一樣,直接split('符號')就可以了,若是有不同的符號,就可以用第二種方法中的re庫。
添加回答
舉報