Write a for loop that prints all elements of a list and their position in the list a 4 7 3 2 5 9

+4 votes
Jul 11, 2019 in Python by anonymous
34,786 views

3 answers to this question.

0 votes

Try this:

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

for i in a:
    print("Element: " + str(i) + " Index: "+ str(a.index(i)))
answered Jul 11, 2019 by Omkar
• 69,220 points
+2 votes
a = [4,7,3,2,5,9]
b = enumerate(a)
for i in b:
    print(i)
answered Jul 16, 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
+3 votes

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 9, 2019 by vinaykumar
• 200 points
Thanks, @Vinaykumar, that was helpful :)

Related Questions In Python

+1 vote
1 answer
0 votes
1 answer

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

answered May 27, 2020 in Python by Niroj
• 82,880 points
3,859 views
0 votes
1 answer

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

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

answered Sep 22, 2018 in Python by SDeb
• 13,300 points
5,000 views
0 votes
2 answers

Data of XYZ company is stored in sorted list. Write a program for searching specific data from that list.

https://www.youtube.com/watch?v=mqaf7vj1AdA This link has the program. It uses ...READ MORE

answered Dec 3, 2019 in Python by Raveendiran
• 980 points
4,764 views
0 votes
1 answer

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

answered Oct 14, 2020 in Python by Gitika
• 65,890 points
4,323 views
0 votes
1 answer
0 votes
1 answer

How to count the number of elements in a list?

To count the number of elements of ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
5,221 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP