Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iteration stops
#4
ok, this should work. See comments

list_nums= [i for i in range(15)] #your line
def fn(ln): #ln will be list_nums but less confusing scope
    output = [] #because you want all the numbers at once
    for i in ln: #proper for loop. Anything with range(len(anything)) there is a better way
        if i<9: 
            output.append(i) #add to list
    return output #this is what you return, not a single value
print(fn(list_nums))
Reply


Messages In This Thread
iteration stops - by d8a988 - Aug-31-2020, 12:12 PM
RE: iteration stops - by perfringo - Aug-31-2020, 03:48 PM
RE: iteration stops - by d8a988 - Aug-31-2020, 04:13 PM
RE: iteration stops - by jefsummers - Sep-01-2020, 09:11 PM
RE: iteration stops - by perfringo - Sep-01-2020, 10:38 PM

Forum Jump:

User Panel Messages

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