Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help to find a command
#2
Use a for loop instead of while:

a = [[10, 20], [30, 40], [50, 60]]
b = 0

for entry in a:
    if b > entry[1]:
        entry.append(0)

    b += 1
    
print (a)
However, I don't believe this accomplishes the objective. This (and the code you provided) can only iterate over "a" once. It appears that you want to iterate indefinitely until you find the list with the smallest value less than 101. To do that, you need a nested loop.

b = 0

while b < 101:
    for entry in a:
       pass
As I understand your objective, a loop is less than ideal. A function that finds the minimum value and another than indexes that value would likely be more effective. The reason being that the nested loop above with a list a = [[0, 102],[1, 512],[1, 200]] will loop 300 times before exiting. Whereas, the functions mentioned above would only loop twice.
Reply


Messages In This Thread
Help to find a command - by andre_fermart - Feb-02-2019, 08:06 AM
RE: Help to find a command - by stullis - Feb-02-2019, 04:15 PM
RE: Help to find a command - by perfringo - Feb-02-2019, 11:47 PM
RE: Help to find a command - by perfringo - Feb-03-2019, 12:51 PM
RE: Help to find a command - by andre_fermart - Feb-04-2019, 08:01 AM
RE: Help to find a command - by perfringo - Feb-04-2019, 09:49 AM
RE: Help to find a command - by andre_fermart - Feb-05-2019, 05:47 AM
RE: Help to find a command - by perfringo - Feb-05-2019, 09:01 AM
RE: Help to find a command - by perfringo - Feb-05-2019, 12:15 PM
RE: Help to find a command - by andre_fermart - Feb-12-2019, 02:34 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020