#🔒 help with case insensitivity
23 messages · Page 1 of 1 (latest)
@inner dirge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!d str.lower
str.lower()```
Return a copy of the string with all the cased characters [[4]](https://docs.python.org/3/library/stdtypes.html#id15) converted to lowercase.
The lowercasing algorithm used is [described in section 3.13 ‘Default Case Folding’ of the Unicode Standard](https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G33992).
you need to compare lower string to lower string
also you can't compare list == str
that will never be true
that's what you are doing in current_users == users.lower()
it may help if you name your variables with proper plurality
for user in new_users: ...
the iteration variable only represents one user at a given moment
so i need to compare the strings from the lists rather than the lists themselves? sorry is just confusing
yes, because they are different types
For example,
try comparing a class of students vs just a student, that's not a fair comparison
You need to keep in mind what you're looking at. A single string eg "Rogers" you can compare it with another string, or see if it in "in" a list of strings.
But because both lists have various cases upper/lower what you would normally do is convert both strings to the same form such as all lowercase, then compare the strings.
Because "Fred" != "freD" but "fred" == "fred"
this has appeared to work although not sure if its still case sensitive
it's still case sensitive because you are comparing it against cased strings in current_users
i also changed the currents_users to lowercase
that would work then
thank you. my outputs were lowercase too. but i changed the
removed*, user =users.lower() and placed user.lower after the if and elif statement
Like if user.lower() in current_users ? That's fine. But note that this: user = user.lower() is also fine in that it doesn't change the content of the new_users list. It just makes a new string in lowercase and points user at that new string. Previously it was pointing at the string from new_users.
Also, you don't need the elif ... not in test - if you get there, you already know it's not in because the in test above failed. So you can just use else.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.