Link to home
Start Free TrialLog in
Avatar of dfernan
dfernanFlag for United States of America

asked on

which lists python

Hi,

Very short question. How do you search (without using for loops) in which position of an array certain condition holds.

I.e., list = [3,4,5,2,4,3,5,6,3,2,1,0]
which(list < 2) = [10, 11] cause in positions 10 and 11 the elements of the list are less than 2.
Avatar of HonorGod
HonorGod
Flag of United States of America image

Don't use "list" as a variable name.

L = [3,4,5,2,4,3,5,6,3,2,1,0]
L.index( 5 )

Tells the location of the list variable that contains the specified value.

Is this what you want?
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfernan

ASKER

No. I want to check for a condition. L.which(>=5) ... index in the list where the values are bigger or equal to 5. In your case, [2,6,7] cause in those positions L is bigger or equal to 5.
Avatar of dfernan

ASKER

sorry now i read ur second answer! yes, that's what i want. thanks!
Great.  Glad to be of some help.

Thanks for the grade & points.

Good luck & have a great day.