0

I have two loops fist is wile loop and first is for loop witch iterate try at dynamic variable I want to stop the wile loop after no more new values are appending to the list in the for loop.

usernames is dynamic it change every time the for loop iterate.

    while n < 10000:
        for each in usernames:
            user_list.append(each)
        if(some condition to break the loop):
           break
mikegrep
  • 27
  • 7

2 Answers2

0

Are you trying to break the loop when you do not receive more items in usernames? You can do that with if len(usernames == 0): break before the for loop.

If you want to test if there are no new items in usernames, you can do either of the following:

if all(user in user_list for user in usernames): break

if set(usernames).issubset(user_list): break

thshea
  • 1,048
  • 6
  • 18
  • 1st one did not work beacouse usernames is bs4.element 2nd also didn`t word and the 3rd will not work beacouse in each iteration usernames change his values with new values and remove old ones. – mikegrep Dec 09 '20 at 15:57
0
while n < 10000:
    working = False
    for each in usernames:
        user_list.append(each)
        working = True
    if not working:
        break
faheem
  • 634
  • 3
  • 5