iterating quickly through list of tuples

前端 未结 5 1688
清歌不尽
清歌不尽 2020-12-05 06:34

I wonder whether there\'s a quicker and less time consuming way to iterate over a list of tuples, finding the right match. What I do is:

# this is a very lon         


        
5条回答
  •  不知归路
    2020-12-05 06:47

    The question is dead but still knowing one more way doesn't hurt:

    my_list = [ (old1, new1), (old2, new2), (old3, new3), ... (oldN, newN)]
    
    for first,*args in my_list:
        if first == Value:
            PAIR_FOUND = True
            MATCHING_VALUE = args
            break
    

提交回复
热议问题