Answers for "know index of element in list python"

43

python find index by value

>>> ["foo", "bar", "baz"].index("bar")
1
Posted by: Guest on November-19-2019
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)]
Posted by: Guest on October-13-2020
6

get index of item in list

list.index(element, start, end)
Posted by: Guest on June-30-2020
1

python get index and value from list

test = [ 'test 1', 'test 2', 'test 3' ]
for index, value in enumerate( test ):
  print( index, value )
Posted by: Guest on October-18-2020
0

get index of all element in list python

indices = [i for i, x in enumerate(my_list) if x == "whatever"]
Posted by: Guest on March-01-2021

Code answers related to "know index of element in list python"

Python Answers by Framework

Browse Popular Code Answers by Language