Match string in python regardless of upper and lower case differences -



Match string in python regardless of upper and lower case differences -

this question has reply here:

case insensitive 'in' - python 6 answers

i'm trying find match value keyword using python. values stored in list (my_list) , in below illustration i'm trying find word 'webcam'. want homecoming word if matched.

using item.find works if case matches (i.e. upper , lower case must correct). want homecoming item regardless of case, however, not wish match instances of string 'webcamnew' using any() method won't work think. know how this..?

my_list = ['webcam', 'home', 'space', 'maybe later', 'webcamnew'] item in my_list: if item.find("webcam") != -1: print item

my_list = ['webcam', 'home', 'space', 'maybe later', 'webcamnew'] item in my_list: if 'webcam' == item.lower() print item.lower()

note: strings immutable in python - doesn't modify string in list.

python

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -