Python列表索引具有不同标志的相同项

Python列表索引具有不同标志的相同项,python,list,nlp,tokenize,Python,List,Nlp,Tokenize,我有一系列代币的清单,以下是清单: [u'the', u'word', u'on', u'the', u'breeze', u'and', u'through', u'the', u'floor', u'deafblind', u'people', u"aren't", u'affected', u'by', u'things', u'that', u'many', u'would', u'consider', u'a', u'distractio', u'', u'this', u'means

我有一系列代币的清单,以下是清单:

[u'the', u'word', u'on', u'the', u'breeze', u'and', u'through', u'the', u'floor', u'deafblind', u'people', u"aren't", u'affected', u'by', u'things', u'that', u'many', u'would', u'consider', u'a', u'distractio', u'', u'this', u'means', u'they', u'can', u'work', u'through', u'lively', u'conversations', u'office', u'tea', u'parties', u'loud', u'music', u'thunderstorms', u'and', u'the', u'lik', u'', u'but', u'create', u'the', u'tiniest', u'of', u'drafts', u'by', u'picking', u'up', u'a', u'sheet', u'of', u'paper', u'or', u'the', u'smallest', u'of', u'vibrations', u'by', u'placing', u'a', u'foot', u'gently', u'on', u'the', u'floor', u'and', u'this', u'might', u'instantly', u'attract', u'the', u'attention', u'of', u'a', u'deafblind', u'perso', u'', u'there', u'are', u'other', u'kinds', u'of', u'distraction', u'', u"i've", u'declared', u'one', u'meeting', u'venue', u'unusable', u'because', u'its', u'wooden', u'floor', u'amplifies', u'vibrations', u'from', u'the', u'fridge', u'in', u'the', u'adjacent', u'kitche', u'', u'the', u'hearing', u'people', u'with', u'me', u'were', u'unaware', u'of', u'the', u'vibration', u'until', u'i', u'drew', u'it', u'to', u'their', u'attention', u'but', u'i', u'found', u'it', u'intolerabl', u'', u'you', u'are', u'what', u'your', u'hands', u'say', u'you', u'are', u'there', u'are', u'many', u'different', u'forms', u'of', u'touch', u'or', u'tactile', u'communicatio', u'', u'deafblind', u'manual', u'is', u'a', u'form', u'of', u'tactile', u'fingerspelling', u'where', u'each', u'letter', u'of', u'the', u'alphabet', u'has', u'a', u'sign', u'that', u'is', u'made', u'against', u'your', u'han', u'', u"there's", u'hands-on', u'signing', u'where', u'a', u'deafblind', u'person', u'puts', u'their', u'hands', u'over', u'the', u'hands', u'of', u'the', u'person', u'they', u'are', u'communicating', u'with', u'to', u'feel', u'the', u'shapes', u'and', u'movements', u'of', u'british', u'sign', u'languag', u'', u'some', u'may', u'use', u'the', u'block', u'alphabet', u'where', u'large', u'capital', u'letters', u'are', u'drawn', u'with', u'a', u'finger', u'onto', u'the', u'pal', u'', u'the', u'way', u'a', u'person', u'touches', u'can', u'say', u'a', u'lot', u'about', u'the', u'', u'from', u'stiffness', u'in', u'the', u'hands', u'to', u'firmness', u'and', u'rhythm', u'or', u'tactile', u'language', u'ability', u'snap', u'judgements', u'can', u'be', u'made', u'about', u"someone's", u'personality', u'or', u'motives', u'just', u'as', u'they', u'can', u'be', u'with', u'a', u'look', u'or', u'a', u'tone', u'of', u'voic', u'', u'deafblind', u'people', u'might', u'not', u'see', u'what', u'others', u'look', u'like', u'or', u'what', u'they', u'are', u'wearing', u'but', u'first', u'impressions', u'still', u'count', u'and', u'these', u'get', u'transmitted', u'by', u'hand', u'', u'tense', u'hands', u'and', u'awkward', u'movements', u'neuroti', u'', u'firm', u'yet', u'relaxed', u'hands', u'with', u'a', u'steady', u'rhythm', u'conscientious', u'and', u'ope', u'', u'like', u'all', u'ways', u'of', u'forming', u'first', u'impressions', u'it', u'can', u'be', u'wrong', u'but', u'who', u'can', u'stop', u'themselves?', u'talking', u'while', u'you', u'eat', u'if', u'you', u'communicate', u'by', u'touch', u'alone', u'it', u'can', u'be', u'difficult', u'to', u'chat', u'with', u'friends', u'over', u'dinne', u'', u'it', u'involves', u'stretching', u'arms', u'and', u'contorting', u'in', u'order', u'to', u'communicate', u'across', u'the', u'table', u'while', u'trying', u'not', u'to', u'knock', u'over', u'drinks', u'and', u'other', u'such', u'messy', u'hazard', u'', u'in', u'a', u'recent', u'blog', u'entry', u'deafblind', u'poet', u'and', u'essayist', u'john', u'lee', u'clark', u'suggests', u'putting', u'people', u'in', u'the', u'middle', u'of', u'the', u'room', u'and', u'the', u'table', u'around', u'the', u'outsid', u'', u"i've", u'seen', u'people', u'communicating', u'with', u'each', u'other', u'like', u'this', u'at', u'events', u'and', u'it', u'looks', u'like', u'a', u'good', u'way', u'to', u'make', u'socialising', u'at', u'mealtimes', u'more', u'accessibl', u'', u'there', u'are', u'more', u'ways', u'to', u'communicate', u'with', u'deafblind', u'people', u'than', u'there', u'are', u'deafblind', u'people', u'communication', u'can', u'happen', u'in', u'lots', u'of', u'different', u'ways', u'-', u'clear', u'speech', u'tactile', u'fingerspelling', u'signing', u'made', u'more', u'easy', u'to', u'see', u'or', u'feel', u'and', u'so', u'o', u'', u'but', u'to', u'complicate', u'things', u'further', u'deafblind', u'people', u'evolve', u'their', u'own', u'variations', u'on', u'these', u'method', u'', u'i', u'communicate', u'using', u'deafblind', u'manual', u'but', u'use', u'five', u'different', u'ways', u'of', u'communicating', u'numbers', u'depending', u'on', u'who', u'i', u'am', u'speaking', u'with', u'and', u'what', u'they', u'kno', u'', u'some', u'people', u'might', u'dot', u'braille', u'numbers', u'on', u'the', u'back', u'of', u'my', u'hand', u'or', u'draw', u'print', u'numbers', u'on', u'my', u'pal', u'', u'or', u'those', u'more', u'familiar', u'with', u'bsl', u'might', u'adapt', u'i', u'', u'for', u'example', u'one', u'is', u'gripping', u'my', u'index', u'finger', u'two', u'is', u'index', u'plus', u'middle', u'three', u'is', u'index', u'plus', u'middle', u'plus', u'rin', u'', u'', u'touch', u'to', u'talk', u'if', u'a', u'deafblind', u'person', u'is', u'touched', u'they', u'assume', u'someone', u'wishes', u'to', u'communicate', u'with', u'them', u'as', u'they', u'cannot', u'see', u'or', u'hear', u'the', u'', u'when', u'someone', u'touches', u'me', u'i', u'try', u'and', u'guess', u'their', u'intentio', u'', u'for', u'example', u'if', u'i', u'am', u'sitting', u'on', u'a', u'train', u'i', u'assume', u"it's", u'the', u'ticket', u'inspector', u'and', u'hold', u'my', u'ticket', u'ou', u'', u'i', u'can', u'speak', u'and', u'am', u'able', u'to', u'explain', u'how', u'the', u'person', u'can', u'communicate', u'with', u'm', u'', u'i', u'offer', u'my', u'braille', u'and', u'print', u'deafblind', u'manual', u'card', u'so', u'they', u'can', u'spell', u'out', u'words', u'to', u'me', u'on', u'my', u'hand', u'', u'but', u'i', u'may', u'be', u'speaking', u'to', u'thin', u'air', u'or', u'to', u'someone', u'who', u'touched', u'me', u'accidentall', u'', u'ironically', u'it', u'can', u'then', u'take', u'ages', u'for', u'them', u'to', u'explain', u'on', u'my', u'card', u'that', u'they', u"don't", u'actually', u'want', u'to', u'tal', u'', u'to', u'get', u'my', u'attention', u'tap', u'my', u'shoulder', u'arm', u'or', u'han', u'', u'stand', u'close', u'if', u'you', u'want', u'to', u'communicate', u'but', u'step', u'back', u'if', u'you', u"don't", u'-', u'i', u'communicate', u'very', u'closely', u'with', u'people', u'but', u'also', u'like', u'a', u'bit', u'of', u'personal', u'spac', u'', u'my', u'colleagues', u'and', u'i', u'invented', u'a', u'secret', u'morse', u'code', u'signal', u'to', u'use', u'with', u'me', u'if', u'they', u'see', u'me', u'travelling', u'alone', u'and', u'looking', u'stressed', u'or', u'ignoring', u'normal', u'tap', u'', u'we', u'invented', u'it', u'after', u'an', u'incident', u'at', u'a', u'london', u'railway', u'station', u'where', u'i', u'was', u'waiting', u'for', u'a', u'colleague', u'one', u'mornin', u'', u'staff', u'and', u'passengers', u'were', u'grabbing', u'at', u'me', u'and', u'not', u'listening', u'to', u'a', u'word', u'i', u'said', u'about', u'communicating', u'with', u'my', u'car', u'', u'i', u'ended', u'up', u'getting', u'very', u'upse', u'', u'when', u'my', u'colleague', u'arrived', u'she', u'tapped', u'me', u'but', u'i', u'spoke', u'out', u'loud', u'to', u'tell', u'whoever', u'it', u'was', u'to', u'leave', u'me', u'alon', u'', u'so', u'we', u'invented', u'the', u'secret', u'morse', u'signal', u'as', u'a', u'quick', u'way', u'for', u'colleagues', u'to', u'say', u'', u"it's", u'ok', u'i', u'know', u'what', u"i'm", u'doing', u'i', u'can', u'communicate', u'with', u'you', u'.', u'though', u"i've", u'been', u'concentrating', u'on', u'touch', u'communication', u'on', u'this', u'page', u"it's", u'worth', u'noting', u'that', u'many', u'people', u'who', u'call', u'themselves', u'deafblind', u'can', u'see', u'and/or', u'hear', u'a', u'littl', u'', u'liz', u'ball', u'works', u'for', u'sense', u'the', u'deafblind', u'charity', u'where', u'she', u'is', u'campaigns', u'involvement', u'office', u'', u'she', u'has', u'been', u'blind', u'from', u'birth', u'but', u'also', u'became', u'deaf', u'at', u'26.']
我尝试使用index()方法为特定项编制索引:

tokens.index(u'or',0)
53
代币.索引(u'或',1)
53
#我像这样一个接一个地转到索引55。
代币.索引(u'or',55)
143

我很好奇它为什么会这样做。既然索引53中只有一个“或”标记,为什么它会返回相同的第54个标记?

列表中有几个
标记,特别是在位置处

[53, 143, 242, 254, 264, 279, 465, 523, 531, 584, 665, 702, 757]
(正如
[pos for pos,word in enumerate(tokens)if word==”或“]
所确定的那样),所以Python的行为符合预期,不是吗

>>> tokens.index(u"or", 53)
53
>>> tokens.index(u"or", 54)
143

作为JonShape,我还获得了
143
start=54

tokens.index
start
参数将启动列表中的搜索,作为列表中的第个索引


请参阅(有关
索引
)和(有关
查找
,因为这里给出了
开始
参数的用法)。

对于
令牌,我得到了
143
。索引(u“或”,54)
,正如预期的那样。这确实有帮助,Pietzscker。谢谢。:)