Jul 10, 2019 in Python 16,970 views

3 answers to this question.

+1 vote

Try this:

```a = [4,7,3,2,5,9]

for i in a:
print("Element: " + str(i) + " Index: "+ str(a.index(i)))```
answered Jul 10, 2019 by
• 69,170 points
+1 vote
```a = [4,7,3,2,5,9]
b = enumerate(a)
for i in b:
print(i)```
answered Jul 15, 2019 by Kei Tee

edited Jul 22, 2019 by Kalgi
What does the enumerate() function do?
It returns a tuple of  each element and its index, including duplicated elements

Try using this question by list comprehension:

a=[4,7,3,2,5,9]
print([x for x in enumerate(a)])

output:

`[(0, 4), (1, 7), (2, 3), (3, 2), (4, 5), (5, 9)]`
answered Dec 8, 2019 by
• 180 points
Thanks, @Vinaykumar, that was helpful :)

+1 vote

I am trying to write a program in python for the occurrences of a character given the start and stop values of that string only using while

Here's the code: check = input("Enter the character: ...READ MORE

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list.

Hi,  num_words_list = len(original_str.split()) original_str.split() - split words in ...READ MORE

Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

–1 vote

What will be the output of below code and why? x=[1,2,3,4,5] print(x.insert(2,3))

If you write x.insert(2,3) and then print x ...READ MORE

Program using re module that loops through the lines of a file or standard input (where each line contains a single word) and prints all words containing two adjacent vowels

Hey, @S, you can have a look at ...READ MORE

) Write a program that sorts a given list, once in ascending and then in descending order, without using the sort() built-in function

Hi, @There, Given an array of size n, ...READ MORE

How do I obtain the index list in a NumPy Array of all the NaN values present using Python?

Hi, it is pretty simple, to be ...READ MORE