0

I want to find the location(s) of a specific item in a list of lists. It should return a number, where the number represents the indexes for a specific instance of the item. For example:

list = [['1', '2', None, '6'], ['7', None, '1', '4']]
getPosition(not None)  #returns [1]

I'm always want to check the third element in every list.

Lvkz
  • 946
  • 14
  • 20
  • Using that duplicate flag, you should be able to figure out how to make it apply for your situation. – idjaw Apr 01 '16 at 17:17
  • Actually, the OP is asking for multiple locations. But why would you want to return `1` in the example? – user2390182 Apr 01 '16 at 17:24
  • @idjaw Take in consideration that is a list of lists, I tried that solution, but couldn't figure it out. Works in only one list though. – Lvkz Apr 01 '16 at 18:47
  • @Lvkz That is why I said you should be able to figure out how to make it apply for your case. It's the same idea, there is just that missing part of list-of-lists you are dealing with. You are ultimately iterating over your list (which you should not be calling list, since it shadows built-in `list`) and then performing an operation on each list inside that. That operation is the duplicate flag I raised. – idjaw Apr 01 '16 at 18:49
  • @schwobaseggl Ok, the scenario is that I have grouped lists, I have a condition, if the column 3 of any of the lists in the group is None, then I pick the last three lists in the group, if at least ONE of the lists in the group have the column 3 not None, then I need to pick the three lists following that index. – Lvkz Apr 01 '16 at 18:49
  • @idjaw Oh, I get it, sorry, I'm new to Python, so I still don't get the concepts of the language. I alread told schwobaseggl what I wanted to accomplish in the previous comment. I'm going to try to extend the OP to my needs. Thanks! – Lvkz Apr 01 '16 at 18:52
  • @Lvkz No need to apologize. If you are still having difficulty, what I suggest doing is putting together code in your question and ensuring that you have put together a [mcve] . Once done, it will be quickly re-opened to assist you further. Good luck. – idjaw Apr 01 '16 at 18:53

0 Answers0