Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2303

Re: In List Query -> None Case Sensitive?

References <BB7D4CEE02C38D499DF7CA5B8D08578721DDDF7E@AMSXMBX01.bskyb.com>
Date 2011-04-01 08:51 +1100
Subject Re: In List Query -> None Case Sensitive?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.45.1301608275.2990.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Apr 1, 2011 at 8:14 AM, Wehe, Marco <Marco.Wehe@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: In List Query -> None Case Sensitive? Chris Angelico <rosuav@gmail.com> - 2011-04-01 08:51 +1100

csiph-web