[Tutor] Problems using .lower()
Steven D'Aprano
steve at pearwood.info
Sun Sep 25 19:43:21 EDT 2016
Hi Jonathan, and welcome!
It is difficult to advise you when we don't know what you are doing
wrong. You should always show us your code: the *minimum* amount of code
that demonstrates the nature of your problem. Otherwise we're just
guessing.
More below:
On Fri, Sep 23, 2016 at 12:19:04PM -0600, Jonathan Curtis wrote:
> Hi,
>
> I am trying to complete an assignment for school and having problems
> getting it to work. I have lists named l_one and and l_two they both have
> a combination of integers and strings. I am supposed to combined the lists
> into a l_three and have no duplicate numbers and strings. Both lists have
> the number 2 and l_one has cat while l_two has Cat. I am having a problem
> being able to get Cat to cat so that it recognizes the duplicate. Pleas
> advise me in this problem. Let me know how you would do it so that I can
> compare it to what I have been trying to do. Thanks for your time and help.
I'll try to guess that you're doing something like this:
# Wrong way, doesn't work.
a = 'cat'
b = 'Cat'
b.lower() # lowercase of b
a == b
# returns False, they are not equal
# Instead, try this:
a = 'cat'
b = 'Cat'
b = b.lower() # set b to the lowercase of b
a == b
# returns True
# Or even better:
a = 'cat'
b = 'Cat'
a.lower() == b.lower()
# returns True
--
Steve
More information about the Tutor
mailing list