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
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…