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

0 votes
Jul 10 in Python by anonymous
225 views

2 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 by Omkar
• 67,480 points
+1 vote
a = [4,7,3,2,5,9]
b = enumerate(a)
for i in b:
    print(i)
answered Jul 15 by Kei Tee

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

Related Questions In Python

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 21, 2018 in Python by SDeb
• 13,160 points
55 views
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 in Python by Nisa
• 1,090 points
15 views
0 votes
1 answer

How do I run a set of code for all the requests in Flask?

Hi, You can use dedicated hooks(decorators) called before ...READ MORE

answered Jun 20 in Python by Shabnam
• 920 points
21 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
64 views
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
660 views
0 votes
1 answer

Join all strings in a list of strings

s = " ".join(myList) #here " " ...READ MORE

answered May 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
17 views
0 votes
0 answers

Storing a list of arrays into a CSV file and retrieving it back in a different program

This is the code that I am ...READ MORE

Jun 6, 2018 in Python by ariaholic
• 7,340 points
40 views
0 votes
1 answer
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,480 points

edited Aug 8, 2018 by Omkar 675 views