Get the index of a unique character in a table (list of lists)?
<p>I have a list of r lists of r elements each.
Let's say <code>r=3</code> then I have something that looks like this:</p>

<pre><code>list=[["o","o","o"],["o","i","o"],["o","o","o"]]
</code></pre>

<p>I would like, using the method """<code>list.index(item)</code>""", to get the index of the "i" elements inside this list. So as a result I should get something I imagine like (x,y) with x for the xth sublist and y for the yth element inside the xth sublist ((1,1) in this case).</p>

<p>I can join the code of my program (game) if you need it later. </p>

<p>If you are looking for a solution that finds an index for all values in the nested list, here is a function for you:</p>

<pre><code>def find_indexes(needle, lst):
    return [(lst_idx, sub_idx) for lst_idx, sublst in enumerate(lst) 
                               for sub_idx, i in enumerate(sublst) 
                                   if i == needle]
</code></pre>

<p>You can use as follows:</p>

<pre><code>&gt;&gt;&gt; lst = [["o","a","o"],["a","i","o"],["o","o","a"]]
&gt;&gt;&gt; find_indexes('a', lst)
[(0, 1), (1, 0), (2, 2)]
</code></pre>

python list python-3.x