Quantcast
Viewing all articles
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 all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>