【发布时间】:2021-06-21 22:06:13
【问题描述】:
由于某种原因 .index 和 .find 在我的程序中不起作用。
基本上,我希望程序根据设置的条件找到列表的索引号。
例如这个列表:
['Synonyms: Pocket Monsters, Indigo League, Adventures on the Orange Islands, The Johto Journeys, Johto League Champions, Master Quest', 'Japanese: ポケットモンスター', 'Type: TV', 'Episodes: 276', 'Status: Finished Airing', 'Aired: Apr 1, 1997 to Nov 14, 2002', 'Premiered: Spring 1997', 'Broadcast: Thursdays at 19:00 (JST)', 'Producers: TV Tokyo, TV Tokyo Music, Studio Jack', 'Licensors: VIZ Media, 4Kids Entertainment', 'Studios: OLM', 'Source: Game', 'Genres: Action, Adventure, Comedy, Kids, Fantasy', 'Duration: 24 min. per ep.', 'Rating: PG - Children', 'Score: 7.341 (scored by 291,570 users)', 'Ranked: #21572', 'Popularity: #287', 'Members: 504,076', 'Favorites: 4,076', '']
我想找到“流派”位置的索引号。我尝试这样做 .index("Genres:") 但没有找到索引号并返回错误。 我需要这个来查找索引号,因为对于本网站上的其他页面,“流派”处于不同的位置
这是我尝试过的,只是返回了一个错误
GIndex = Information.index("Genres")
print (Information[GIndex])
Genre = (Information[GIndex])
【问题讨论】:
-
虽然列表中没有值为
"Genres"的元素。 -
您的数据表明您最好首先使用 dict。
标签: python