In List Query -> None Case Sensitive?

Chris Angelico rosuav at gmail.com
Thu Mar 31 17:51:12 EDT 2011


On Fri, Apr 1, 2011 at 8:14 AM, Wehe, Marco <Marco.Wehe at bskyb.com> wrote:
>
> I am doing a search through a list of files but the text the casing doesn't match. My list is all upper case but the real files are all different. Is there a smooth way of searching through the list without going full on regular expressions?
>
>                                     if iFile in media:

If you know they're *all* uppercase, the easiest way is to replace
this line with:

if iFile.upper() in media:

It's not case insensitive per se. For true case insensitivity, force
media[] to be all-uppercase too:

media=[f.upper() for f in media]

Or you can equally use lower() instead of upper().

Chris Angelico



More information about the Python-list mailing list