Find an Exact Tuple Match in a List of Tuples and Return Its Index

This question already has an answer here:

  • Finding the index of an item given a list containing it in Python 23 answers

  • 使用list.index

    >>> TupList = [('ABC D','235'),('EFG H','462')]
    >>> TupList.index((u'EFG H',u'462'))
    1
    

    我认为你可以这样做

    TupList = [('ABC D','235'),('EFG H','462')]
    if ('ABC D','235') in TupList:
       print TupList.index(i)
    
    链接地址: http://www.djcxy.com/p/28108.html

    上一篇: 如何在Python中的两个列表的交集中选择元素

    下一篇: 在元组列表中查找精确的元组匹配并返回其索引