0
How can I print indexes number of a given number in the list?
L=[1,3,8,3,12,3] X=3 output:1 3 5
13 Respostas
+ 5
for i,j in enumerate(L):
if j==X:
print(i)
+ 5
If you like to have the indexes found stored in a list, you can do like this:
L=[1,3,8,3,12,3]
res = [ind for ind,num in enumerate(L) if num == 3]
print(res) #output: [1, 3, 5]
+ 2
L.index[3]
or
x=len(L)
for I in range(x):
if L[I] ==3:
print(I)
0
and use this to print all in the same line
print(i ,end="")
Out put:
1 3 8 3 12 3
0
You can make a loop to iterate from 0 to list length.
In each iteration you check if the wanted item is located at the index, which is the iteration number.
If it is, print the iteration number.
0
I do that but it he print 1 11 -->the first index
0
I want the indexes 3 in list
0
L=[1,3,8,3,12,3]
X=int(input())
for i in L:
if x==i:
Print(L. index(I))
0
It print
1
1
1
0
Thanks olivia it's work đ
0
Your welcome đ
0
for i in range(5):
if L[i]==value:
print(i)
- 1
L=[1,3,8,3,12,3]
for i in L:
print(i)
out put:
1
3
8
3
12
3