Python: Indexing list for element in nested list
Posted
by aquateenfan
on Stack Overflow
See other posts from Stack Overflow
or by aquateenfan
Published on 2010-03-09T00:53:06Z
Indexed on
2010/03/09
1:06 UTC
Read the original article
Hit count: 358
I know what I'm looking for. I want python to tell me which list it's in.
Here's some pseudocode:
item = "a"
nested_list = [["a", "b"], ["c", "d"]]
list.index(item) #obviously this doesn't work
here I would want python to return 0 (because "a" is an element in the first sub-list in the bigger list). I don't care which sub-element it is. I don't care if there are duplicates, e.g., ["a", "b", "a"] should return the same thing as the above example.
Sorry if this is a dumb question. I'm new to programming.
© Stack Overflow or respective owner