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 change a dataframe column to lower case zhujp98 5 4,329 Oct-29-2019, 06:42 PM
Last Post: zhujp98
  Retrieve protocol in lower case Variables 1 1,202 May-02-2019, 04:46 AM
Last Post: Larz60+
  How to only extract upper or lower triangular matrix into tabular form SriRajesh 3 15,514 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 1,487 Dec-27-2018, 07:07 AM
Last Post: perfringo
  How recursion function is applied? dukoolsharma 2 1,586 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 2,847 Sep-05-2017, 02:25 PM
Last Post: ichabod801
  Applied Graph Theory daniellemmoore 2 2,514 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