Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2320
| Date | 2011-04-01 01:13 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: In List Query -> None Case Sensitive? |
| References | <BB7D4CEE02C38D499DF7CA5B8D08578721DDDF7E@AMSXMBX01.bskyb.com> <4D94FAB9.8020402@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.56.1301616901.2990.python-list@python.org> (permalink) |
On 31/03/2011 23:05, Ethan Furman wrote: > Wehe, Marco 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? >> >> path = "V:\\Jinsy\\incoming\\assets" >> media=["LIHOU ISLAND.MOV", "MVI_1449.MOV"] >> def FindMedia(path): >> result = [] >> for root, dirs, files in os.walk(path): >> for iFile in files: >> if iFile in media: >> filePath = os.path.join(root, iFile) >> result.append(filePath) >> return result >> for filePath in FindMedia(path): >> log(filePath) > > > Change > > if iFile in media: > > to > > if iFile.upper() in media: > > and keep media all upper-case. > <aside> Converting to uppercase or lowercase doesn't always work as desired. For example, when using Turkish you can have problems, because the Turkish variant of the Latin alphabet splits i/I into two different letters, namely dotted "i" (uppercase is "İ" or "\u0130") and dotless "I" (lowercase is "ı" or "\u0131"). </aside>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: In List Query -> None Case Sensitive? MRAB <python@mrabarnett.plus.com> - 2011-04-01 01:13 +0100
csiph-web