HakariDo
HakariDo

Reputation: 287

Case-insensitive matching of dictionary values

Re .lower usage (?), how can I make case-insensitive matching for dictionary values? For example, config[camID]["media_file"]] should match both, lowercase and uppercase extensions, even though the dictionary has lowercase only.

1 line from dictionary:

config['d5']['media_file'] = ('nef', 'jpg', 'avi')

Code:

for f in files:
     if any([f.endswith(x) for x in config[camID]["media_file"]]):
         os.rename(os.path.join(path, f), 
                   os.path.join(path, "%s%s%s" % (config[camID]['cam_name'], "_", f)))

(If there is an "in-dictionary" solution (i.e, instead in the code), that would be also interesting to know.)

Upvotes: 0

Views: 813

Answers (1)

Gui
Gui

Reputation: 801

You need to convert the data to a standard before stores in the dict (like lower). After storage there is no way to search for case insensitive inside dict ou set, because this search are made by hash.

Upvotes: 2

Related Questions