How can I change the iteration variable inside a for loop in python?

0 votes
Can you give an example using a nested for loop?
Jun 10 in Python by Waseem
• 3,520 points
20 views

1 answer to this question.

0 votes

Assume you have a list of lists:

my_list = [ [1,2,3] , [4,5,6] , [7,8,9] ]

for lists in my_list:

    for val in lists:

        print(val)

First loop will go through each list inside my_list and the second loop will go through each element in each list

answered Jun 10 by Shubham Bansal

Related Questions In Python

0 votes
1 answer

How can I get the count of a list in Python?

len() >>> mylist=[] >>> print len(mylist) 0 READ MORE

answered Dec 12, 2018 in Python by charlie_brown
• 7,710 points
57 views
0 votes
1 answer

How can I change the data type to string in Python?

You can use str(variablename) This is called conversion ...READ MORE

answered Dec 17, 2018 in Python by Shuvodip
44 views
0 votes
1 answer

How can I lookup hostname using the IP address with a timeout in Python?

Good question. I actually was stuck with ...READ MORE

answered Feb 6 in Python by Nymeria
• 3,500 points
58 views
0 votes
1 answer

How can I find the square of a number in python?

You can use the exponentiation operator or ...READ MORE

answered May 20 in Python by Mohammad
• 1,500 points
21 views
0 votes
0 answers

How can I use the sleep function in a python program?

Can you give a sample code for ...READ MORE

May 23 in Python by Waseem
• 3,520 points

edited May 24 by Omkar 16 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 134 views
+4 votes
6 answers