如何在列表中找到索引列表的位置

时间:2019-02-19 16:16:45

标签: python list indexing

pola2 = [['%3C','%28'],['%3C','document.cookie','%3B'],['%3C','%28','%27','4'],['%3C','document.cookie','%3B','4','5'],['%3C','document.cookie','%3B','4','5','6']]
#find the longest list in list
a = max(pola2, key=len)
print a
#result ['%3C', 'document.cookie', '%3B', '4', '5', '6']
#how if end of result is index "4" or position "5"

如何打印print apola2列表中的索引4或位置5中显示的结果?

1 个答案:

答案 0 :(得分:0)

尝试下面的代码:

pola2 = [['%3C','%28'],['%3C','document.cookie','%3B'],['%3C','%28','%27','4'],['%3C','document.cookie','%3B','4','5'],['%3C','document.cookie','%3B','4','5','6']]
a = max(pola2, key=len)
print pola2.index(a)

应该工作正常。这个问题有点重复,请参阅:Finding the index of an item given a list containing it in Python