Apr-15-2020, 09:51 PM
The quick way is to change new_accounts into a set instead of a list; sets store unique values only.
existing_accounts = ["Marcis", "John", "Tim"] new_accounts = ["Sarah", "Marcis", "Tim", "Marcis"] for new_account in set(new_accounts): if new_account in existing_accounts: print(new_account + " is already taken!") new_accounts.remove(new_account) else: print (new_account + " you are now registered.") existing_accounts.append(new_account) new_accounts.remove(new_account) print(existing_accounts) print(new_accounts)Something to be aware of when iterating over lists: alterations to the list inside the loop can cause problems. For instance, if Tim did not have an existing account, he would likely not be listed in new_accounts at the end. This is due to the indices of the contents changing because of the removal of Marcis, but the index for the loop doesn't adjust accordingly. Remove Tim from existing_accounts and run it again; you should find a problem.