index()-like behavior that returns all occurences...

Lorin Hochstein hawkestein at my-deja.com
Wed Dec 19 17:12:14 EST 2001


I've got a list of lists, something like this:

x = [ [1], [1,2], [], [1,2,3], [], [2], [12] ]

I want to find the index of all of the empty lists. In other words, I'd 
like a function foo that would behave like this:

 >> foo(x)
[2 4]

I know there's an index method of list, such that x.index([]) would 
return "2". But I want all of the indexes, not just the first one. Is 
there a simple way to do this (besides the obvious for-loop approach)?

Lorin (new to Python but thoroughly enjoying it so far)




More information about the Python-list mailing list