[Python] What is the most efficient way of finding the index of an item from a list of lists...

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following list:

    ['F1', [10, 'r'], 'F2', 'F5', [15, 'w'] 'F3', [14, 'r'], 'F4']

    I want the index of the list [15, 'w'] using the value 15.
    What would be the most efficient way of obtaining the index value? (answer should be 4)

    I tried using lambda x: x[0] inside the python .index() function but could not figure out anything of value. I do not want to use loops and if statements. Is there a way to efficiently carry out this task using python's in-built functionalities?

    The first value of every list will be unique for all lists inside the main list.

    Edit:
    By saying "I do not want to use loops" I meant nested loops and if-statements which increase the complexity of the solution, since I will be working with very large lists in many places of the code. So one loop would be fine as long as the complexity isn't greatly increased.

    Continue reading...

Compartilhe esta Página