Quantcast
Viewing latest article 1
Browse Latest Browse All 16

Answer by Jason R. Coombs for How do I do a case-insensitive string comparison?

Consider using FoldedCase from jaraco.text:

>>> from jaraco.text import FoldedCase>>> FoldedCase('Hello World') in ['hello world']True

And if you want a dictionary keyed on text irrespective of case, use FoldedCaseKeyedDict from jaraco.collections:

>>> from jaraco.collections import FoldedCaseKeyedDict>>> d = FoldedCaseKeyedDict()>>> d['heLlo'] = 'world'>>> list(d.keys()) == ['heLlo']True>>> d['hello'] == 'world'True>>> 'hello' in dTrue>>> 'HELLO' in dTrue

Viewing latest article 1
Browse Latest Browse All 16

Trending Articles