从\ n和\ t中分割出一个字符串

时间:2014-09-25 12:47:35

标签: python split

这些是我想要拆分成列表的动词列表。

'awake\nawoke\nawoken\nbe\nwas, were\nbeen\nbeat\nbeat\nbeaten\nbecome\nbecame\nbecome\nbegin\nbegan\nbegun\nbend\nbent\nbent\nbet\nbet\nbet\nbid\nbid\nbid\nbite\nbit\nbitten\nblow\nblew\nblown\nbreak\nbroke\nbroken\nbring\nbrought\nbrought\nbroadcast\nbroadcast\nbroadcast\nbuild\nbuilt\nbuilt\nburn\nburned/burnt\nburned/burnt\nbuy\nbought\nbought\ncatch\ncaught\ncaught\nchoose\nchose\nchosen\ncome\ncame\ncome\ncost\ncost\ncost\ncut\ncut\ncut\ndig\ndug\ndug\ndo\ndid\ndone\ndraw\ndrew\ndrawn\ndream\ndreamed/dreamt\ndreamed/dreamt\ndrive\ndrove\ndriven\ndrink\ndrank\ndrunk\neat\nate\neaten\nfall\nfell\nfallen\nfeel\nfelt\nfelt\nfight\nfought\nfought\nfind\nfound\nfound\nfly\nflew\nflown\nforget\nforgot\nforgotten\nforgive\nforgave\nforgiven\nfreeze\nfroze\nfrozen\nget\ngot\ngot (sometimes gotten)\ngive\ngave\ngiven\ngo\nwent\ngone\ngrow\ngrew\ngrown\nhang\nhung\nhung\nhave\nhad\nhad\nhear\nheard\nheard\nhide\nhid\nhidden\nhit\nhit\nhit\nhold\nheld\nheld\nhurt\nhurt\nhurt\nkeep\nkept\nkept\nknow\nknew\nknown\nlay\nlaid\nlaid\nlead\nled\nled\nlearn\nlearned/learnt\nlearned/learnt\nleave\nleft\nleft\nlend\nlent\nlent\nlet\nlet\nlet\nlie\nlay\nlain\nlose\nlost\nlost\nmake\nmade\nmade\nmean\nmeant\nmeant\nmeet\nmet\nmet\npay\npaid\npaid\nput\nput\nput\nread\nread\nread\nride\nrode\nridden\nring\nrang\nrung\nrise\nrose\nrisen\nrun\nran\nrun\nsay\nsaid\nsaid\nsee\nsaw\nseen\nsell\nsold\nsold\nsend\nsent\nsent\nshow\nshowed\nshowed/shown\nshut\nshut\nshut\nsing\nsang\nsung\nsit\nsat\nsat\nsleep\nslept\nslept\nspeak\nspoke\nspoken\nspend\nspent\nspent\nstand\nstood\nstood\nswim\nswam\nswum\ntake\ntook\ntaken\nteach\ntaught\ntaught\ntear\ntore\ntorn\ntell\ntold\ntold\nthink\nthought\nthought\nthrow\nthrew\nthrown\nunderstand\nunderstood\nunderstood\nwake\nwoke\nwoken\nwear\nwore\nworn\nwin\nwon\nwon\nwrite\nwrote\nwritten'

如何拆分字符串中的每个单词?

2 个答案:

答案 0 :(得分:5)

如果您需要根据\n\t进行拆分,则可能需要使用此类re.split

import re
print re.split(r'[\n\t]+', data)

答案 1 :(得分:2)

只需使用splitlines

即可
s = 'awake\nawoke\nawoken\nbe\nwas, were\nbeen\nbeat\nbeat\nbeaten\nbecome\nbecame\nbecome\nbegin\nbegan\nbegun\nbend\nbent\nbent\nbet\nbet\nbet\nbid\nbid\nbid\nbite\nbit\nbitten\nblow\nblew\nblown\nbreak\nbroke\nbroken\nbring\nbrought\nbrought\nbroadcast\nbroadcast\nbroadcast\nbuild\nbuilt\nbuilt\nburn\nburned/burnt\nburned/burnt\nbuy\nbought\nbought\ncatch\ncaught\ncaught\nchoose\nchose\nchosen\ncome\ncame\ncome\ncost\ncost\ncost\ncut\ncut\ncut\ndig\ndug\ndug\ndo\ndid\ndone\ndraw\ndrew\ndrawn\ndream\ndreamed/dreamt\ndreamed/dreamt\ndrive\ndrove\ndriven\ndrink\ndrank\ndrunk\neat\nate\neaten\nfall\nfell\nfallen\nfeel\nfelt\nfelt\nfight\nfought\nfought\nfind\nfound\nfound\nfly\nflew\nflown\nforget\nforgot\nforgotten\nforgive\nforgave\nforgiven\nfreeze\nfroze\nfrozen\nget\ngot\ngot (sometimes gotten)\ngive\ngave\ngiven\ngo\nwent\ngone\ngrow\ngrew\ngrown\nhang\nhung\nhung\nhave\nhad\nhad\nhear\nheard\nheard\nhide\nhid\nhidden\nhit\nhit\nhit\nhold\nheld\nheld\nhurt\nhurt\nhurt\nkeep\nkept\nkept\nknow\nknew\nknown\nlay\nlaid\nlaid\nlead\nled\nled\nlearn\nlearned/learnt\nlearned/learnt\nleave\nleft\nleft\nlend\nlent\nlent\nlet\nlet\nlet\nlie\nlay\nlain\nlose\nlost\nlost\nmake\nmade\nmade\nmean\nmeant\nmeant\nmeet\nmet\nmet\npay\npaid\npaid\nput\nput\nput\nread\nread\nread\nride\nrode\nridden\nring\nrang\nrung\nrise\nrose\nrisen\nrun\nran\nrun\nsay\nsaid\nsaid\nsee\nsaw\nseen\nsell\nsold\nsold\nsend\nsent\nsent\nshow\nshowed\nshowed/shown\nshut\nshut\nshut\nsing\nsang\nsung\nsit\nsat\nsat\nsleep\nslept\nslept\nspeak\nspoke\nspoken\nspend\nspent\nspent\nstand\nstood\nstood\nswim\nswam\nswum\ntake\ntook\ntaken\nteach\ntaught\ntaught\ntear\ntore\ntorn\ntell\ntold\ntold\nthink\nthought\nthought\nthrow\nthrew\nthrown\nunderstand\nunderstood\nunderstood\nwake\nwoke\nwoken\nwear\nwore\nworn\nwin\nwon\nwon\nwrite\nwrote\nwritten'

s.splitlines()
['awake', 'awoke', 'awoken', 'be', 'was, were', 'been', 'beat', 'beat', 'beaten', 'become', 'became', 'become', 'begin', 'began', 'begun', 'bend', 'bent', 'bent', 'bet', 'bet', 'bet', 'bid', 'bid', 'bid', 'bite', 'bit', 'bitten', 'blow', 'blew', 'blown', 'break', 'broke', 'broken', 'bring', 'brought', 'brought', 'broadcast', 'broadcast', 'broadcast', 'build', 'built', 'built', 'burn', 'burned/burnt', 'burned/burnt', 'buy', 'bought', 'bought', 'catch', 'caught', 'caught', 'choose', 'chose', 'chosen', 'come', 'came', 'come', 'cost', 'cost', 'cost', 'cut', 'cut', 'cut', 'dig', 'dug', 'dug', 'do', 'did', 'done', 'draw', 'drew', 'drawn', 'dream', 'dreamed/dreamt', 'dreamed/dreamt', 'drive', 'drove', 'driven', 'drink', 'drank', 'drunk', 'eat', 'ate', 'eaten', 'fall', 'fell', 'fallen', 'feel', 'felt', 'felt', 'fight', 'fought', 'fought', 'find', 'found', 'found', 'fly', 'flew', 'flown', 'forget', 'forgot', 'forgotten', 'forgive', 'forgave', 'forgiven', 'freeze', 'froze', 'frozen', 'get', 'got', 'got (sometimes gotten)', 'give', 'gave', 'given', 'go', 'went', 'gone', 'grow', 'grew', 'grown', 'hang', 'hung', 'hung', 'have', 'had', 'had', 'hear', 'heard', 'heard', 'hide', 'hid', 'hidden', 'hit', 'hit', 'hit', 'hold', 'held', 'held', 'hurt', 'hurt', 'hurt', 'keep', 'kept', 'kept', 'know', 'knew', 'known', 'lay', 'laid', 'laid', 'lead', 'led', 'led', 'learn', 'learned/learnt', 'learned/learnt', 'leave', 'left', 'left', 'lend', 'lent', 'lent', 'let', 'let', 'let', 'lie', 'lay', 'lain', 'lose', 'lost', 'lost', 'make', 'made', 'made', 'mean', 'meant', 'meant', 'meet', 'met', 'met', 'pay', 'paid', 'paid', 'put', 'put', 'put', 'read', 'read', 'read', 'ride', 'rode', 'ridden', 'ring', 'rang', 'rung', 'rise', 'rose', 'risen', 'run', 'ran', 'run', 'say', 'said', 'said', 'see', 'saw', 'seen', 'sell', 'sold', 'sold', 'send', 'sent', 'sent', 'show', 'showed', 'showed/shown', 'shut', 'shut', 'shut', 'sing', 'sang', 'sung', 'sit', 'sat', 'sat', 'sleep', 'slept', 'slept', 'speak', 'spoke', 'spoken', 'spend', 'spent', 'spent', 'stand', 'stood', 'stood', 'swim', 'swam', 'swum', 'take', 'took', 'taken', 'teach', 'taught', 'taught', 'tear', 'tore', 'torn', 'tell', 'told', 'told', 'think', 'thought', 'thought', 'throw', 'threw', 'thrown', 'understand', 'understood', 'understood', 'wake', 'woke', 'woken', 'wear', 'wore', 'worn', 'win', 'won', 'won', 'write', 'wrote', 'written']