get all index of item in list python
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
get all index of item in list python
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
python find index by value
>>> ["foo", "bar", "baz"].index("bar")
1
find index of sublist in list python
greeting = ['hello','my','name','is','bob','how','are','you','my','name','is']
def find_sub_list(sl,l):
results=[]
sll=len(sl)
for ind in (i for i,e in enumerate(l) if e==sl[0]):
if l[ind:ind+sll]==sl:
results.append((ind,ind+sll-1))
return results
print find_sub_list(['my','name','is'], greeting)
# [(1, 3), (8, 10)]
find an index of an item in a list python
#Example List
list = ['apples', 'bannas', 'grapes']
#Use Known Entites In The List To Find The Index Of An Unknown Object
Index_Number_For_Bannas = list.index('apples')
#Print The Object
print(list[Index_Number_For_Bannas])
python index method
my_string = "Hello World!"
my_string.index("l") # outputs 2
# this method only outputs the index of the first "l" value in the string/list
how to get index of element in list
# Python3 program for demonstration
# of list index() method
list1 = [1, 2, 3, 4, 1, 1, 1, 4, 5]
# Will print the index of '4' in list1
print(list1.index(4))
list2 = ['cat', 'bat', 'mat', 'cat', 'pet']
# Will print the index of 'cat' in list2
print(list2.index('cat'))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us