I suspect this is a basic question(but I tried to google and search SO with no luck).
I have a list: [1, 2,3,4]
and I want to know where in the list the value of 3 is..but without using a for loop to go through the entire list. Is that possible? I’m already going through a very large list and want to minimize the number of loops through the entire list.
Is this possible?
.index()will raise an IndexError if it cannot find the value you are looking for.Keep in mind if you are doing lots of
.index()look-ups on large lists, that it can be very slow — Python has to brute-force loop through the lists just like you were doing.