1
我有一个名单,我需要检索词的位置,到目前为止,我,我想打印位置字是海如何从列表中检索单词的位置?
Sentence = [she , sells , sea , shells ,on , the, sea , shore]
print (sentence.find(sea))
什么我做错了任何想法?
我有一个名单,我需要检索词的位置,到目前为止,我,我想打印位置字是海如何从列表中检索单词的位置?
Sentence = [she , sells , sea , shells ,on , the, sea , shore]
print (sentence.find(sea))
什么我做错了任何想法?
使用列表的index()
功能:
Sentence = ["she" , "sells" , "sea" , "shells" ,"on" , "the", "sea" , "shore"]
print Sentence.index("sea")
列表的索引是基于零的,因此结果是2
。
欢迎来到Stack Overflow!你似乎在要求某人为你写一些代码。堆栈溢出是一个问答网站,而不是代码写入服务。请[see here](http://stackoverflow.com/help/how-to-ask)学习如何编写有效的问题。 –
老实说,这是一个简单的解决方案的一个非常简单的问题。我认为它不值得下调或被关闭,除非它是重复的。 – Vorticity