2
for items in things:
    while inputFloat != 0:
        thingsBack[][1]=inputFloat//things[]
        inputFloat=inputFloat-(things[]*thingsBack[][1])

things is a list of n elements, while thingsBack is a list with n sub-lists. I want both things and thingsBack to start at the 0th element and to loop through the recursion. The calculation inputFloat//things[] only changes the 1 index of the j-th sublist in thingsBack. i know [] is invalid syntax, but used for illustrative purposes.

it seems like there would be an obvious solution, but I am not seeing it.

2 Answers2

2

Taking a guess, I think you are looking for the index of the current item in your for loop?

for index, items in enumerate(things):
    # do stuff using index

Check this out:

Accessing the index in Python 'for' loops

Community
  • 1
  • 1
Maximus
  • 1,244
  • 10
  • 12
0

You can use several different approaches

  • A range based for loop

    for i in range(len(things)):
        thingsBack[i][1] = inputFloat // things[i]
        # etc.
    
  • Loop over the elements of things using enumerate, to also get the index

    for i, thing in enumerate(things):
        thingsBack[i][1] = inputFloat // thing
        # etc.
    
  • Loop over a zipped list of things and thingsBack

    for thing, thingBack in zip(things, thingsBack):
        thingBack[1] = inputFloat // thing
        # etc.
    
Jan Christoph Terasa
  • 5,781
  • 24
  • 34