Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop problem
#1
Hi, I'm starting learning Python and there is a task in which I've found a problem and I hope somebody could help me:
The task is to check whether names of new users on some website is different than current users and show message if it already exists. It has to ignore capital letters. And there is the problem:

current_users = ['admin','USer1','UseR2','User3','user4']
new_users = ['User0','User1','User2','User5', 'User6']

for new_user in new_users:
    new_user=new_user.lower()
    current_users_low=current_users[:]
    for current_user in current_users_low:
        current_user=current_user.lower()
    if new_user in current_users_low:
        print("That name is already taken! Put another name.")
    else:
        new_user=new_user.title()
        print(f"Welcome {new_user}")
Current user is made to lower letters it 2nd for loop, but in the list current_users_low there are again capital letters. My question is how can I update this list to lower letters, so I could check it with new_users ignoring capital letters ?

*Problem solved, but I can't delete this post (I created empty list and added each current user to that list in forloop)
Reply
#2
If only there was a way to convert strings to upper or lower case letters.

There is a better way to find the intersection of two sets than looping. Python has a collection class called a set, and it supports set operations.
Milczek likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with for loop Intellectual11 5 3,902 Aug-26-2021, 04:14 PM
Last Post: naughtyCat
  Trivia2 Loop problem? milll929 3 4,707 Jun-07-2017, 12:46 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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