We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental level, click here for more details.

It is very often that items in list should be moved to another list in Python programming. For example, users trying to register on a website can only be moved to a verified user list after certain conditions are met. In such circumstance, a while loop can be applied.

#a list of new users waiting to verify
new_users = ['Wilson', 'Mico', 'Shirley', 'Dudu', 'Miaomiao','dudu']
#en empty list for verified user
verified_users = []
#while loop to verify every new user
#if the lower form of the new user is same as one of the user in 
#verified user, then this user can not go into verified user list
while new_users:
    new_user = new_users.pop()
    
    if new_user.lower() not in verified_users:
        verified_users.append(new_user.lower())
    else:
        print(new_user + " is already in the list")
#output
Dudu is already in the list
# Display all verified users.
print("\nThese are all the verified users now:")
for verify_user in verified_users:
    print(verify_user)
#output
These are all the verified users now:
dudu
miaomiao
shirley
mico
wilson

You can also watch videos on our YouTube channel for more understanding of Python programming skills.


0 Comments

Leave a Reply

Avatar placeholder