To specify indexes in order when the list has duplicate values

Asked 2 years ago, Updated 2 years ago, 77 views

a= ["Ga", "Ga", "Ga", "Na"] for i in a : print(a.index(i))

The output value is 0 0 0 3 It's an index

0 1 2 3 How can I change it to

list

2022-09-22 20:15

1 Answers

 a= ["Ga", "Ga", "Ga", "Na"]
for k, v in enumerate(a): 
    print(k, v)

where k is the index v is the value.


2022-09-22 20:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.