看板 Python 關於我們 聯絡資訊
想要的結果為 input="批踢踢實業坊" output=["批踢","踢踢","踢實","實業","業坊 "] (取Bigram) 如果是英文的話,因為有空格可用split()來作,但unicode變成 '\xa7\xe5\xbd\xf0\xbd\xf0\xb9\xea\xb7~\xa7{' 不知道該怎麼切。 想說如果可以切成["批","踢","踢","實","業","坊"],應該就可以得到output 我用的是python2.6 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.67.21
uranusjr:直接 list('批踢踢實業坊') 就行了... 12/29 21:52
uranusjr:啊不對這樣會變成半個字, 想錯了... 12/29 21:53
uranusjr:要用 unicode 類別才行 http://codepad.org/ocoHJiBj 12/29 21:55
windker:感謝回答 12/29 22:11
grtfor:切中文盡量都轉成unicode處理,用正規表示法切時要特別小心 12/30 18:02
apua:L=list(INPUT.decode('big5')) 12/30 22:00
apua:OUTPUT=[(L[i]+L[i+1]).encode('utf8') for i in xrange( \ 12/30 22:01
apua:len(L)-1)] 12/30 22:01
gasolin:for i in list(u"批踢踢實業坊"): print i 01/07 13:38