Finding the index of an element in nested lists in python
问题 I am trying to get the index of an element in nested lists in python - for example [[a, b, c], [d, e, f], [g,h]] (not all lists are the same size). I have tried using strand_value= [x[0] for x in np.where(min_value_of_non_empty_strands=="a")] but this is only returning an empty list, even though the element is present. Any idea what I'm doing wrong? 回答1: def find_in_list_of_list(mylist, char): for sub_list in mylist: if char in sub_list: return (mylist.index(sub_list), sub_list.index(char))