How to find the position of element in a list of lists?

Let's say I have a list of lists: [['a','b','c'], ['a','b','c'], ['b','a','d']]. What code would allow me to get the the coordinates of 'a' (index, row) as a list of tuples? Ex: [(0,0), (1,0), (1,2)]?

1 Answer

  • EddieJ
    Lv 7
    3 weeks ago

    Usually, the first thing you would do would be to assign your list of lists to a variable.

    Then you would use a <for> loop to go through each element of the main list.

    Then you could use the .index ('a') method.

    • EddieJ
      Lv 7
      3 weeks agoReport

      Don't say you've done that -- SHOW us what you've done.

      result = []
      for n, sub in enumerate (myList): result.append ((n, sub.index (search)))

Still have questions? Get answers by asking now.