Python Forum
lower() applied at in operator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lower() applied at in operator
#1
Is there a way to use lower() or casefold() at the "in" operator like
if 'string' in these_list.lower()

I know this is not possible, but there should be a way to achieve this in an elegant way
Reply
#2
You can use like:
if val.lower() in this_list:
but not the way you try. lower must be applied to individual item, therefore list doesn't qualify.
Reply
#3
I've the problem on the list or dictionary side which I read from a file as csv, josn, etc
Reply
#4
As Larz60+ told you, you can't call lower on a list (or a dictionary) for that matter. It doesn't make sense does it? Turning something to lowercase only makes sense if that something is a string. A list of strings is not a string! If you want to do that to all the items in a list, for example, either write a for loop, or a list comprehension to produce a new list.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to apply function lower() to the list? Toltimtixma 2 756 Feb-10-2023, 05:15 PM
Last Post: Toltimtixma
  Beginner Higher Lower Game wallytan 2 1,538 Sep-29-2022, 05:14 PM
Last Post: deanhystad
  How to change a dataframe column to lower case zhujp98 5 6,208 Oct-29-2019, 06:42 PM
Last Post: zhujp98
  Retrieve protocol in lower case Variables 1 2,331 May-02-2019, 04:46 AM
Last Post: Larz60+
  How to only extract upper or lower triangular matrix into tabular form SriRajesh 3 25,465 Jan-04-2019, 01:21 AM
Last Post: scidam
  Strip does not work when applied on a string read from a text file. susmis666 1 2,336 Dec-27-2018, 07:07 AM
Last Post: perfringo
  How recursion function is applied? dukoolsharma 2 2,582 Dec-06-2018, 12:35 PM
Last Post: himanibansal
  How do I loop through a list and delete numerical elements that are 1 lower/higher? neko 4 4,255 Sep-05-2017, 02:25 PM
Last Post: ichabod801
  Applied Graph Theory daniellemmoore 2 3,604 Mar-14-2017, 09:47 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

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