Python二列出查找索引值

Python二列出查找索引值,第1张

概述listEx = ['cat *(select: "Brown")*', 'dog', 'turtle', 'apple']listEx2 = ['hampter',' bird', 'monkey', 'banana', 'cat']for j in listEx2: for i in listEx: if j in i: print lis
ListEx = ['cat *(select: "brown")*','dog','turtle','apple']ListEx2 = ['hampter',' bird','monkey','banana','cat']for j in ListEx2:    for i in ListEx:        if j in i:            print ListEx.index(j)

我想要完成的是在ListEx中搜索ListEx2中的项目.如果在ListEx中找到ListEx2中的项目,我想知道如何打印ListEx中ListEx2中找到的项目的索引值.谢谢!

解决方法 只需使用枚举:

ListEx = ['cat *(select: "brown")*','cat']for j in ListEx2:    for pos,i in enumerate(ListEx):        if j in i:            print j,"found in",i,"at position",pos,"of ListEx"

这将打印

cat found in cat *(select: "brown")* at position 0 of ListEx
总结

以上是内存溢出为你收集整理的Python二列出查找索引值全部内容,希望文章能够帮你解决Python二列出查找索引值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1192632.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存