Case insensitive 'in' - Python
问题 I love using the expression if \'MICHAEL89\' in USERNAMES: ... where USERNAMES is a list Is there any way to match items with case insensitivity or do I need to use a custom method? Just wondering if there is need to write extra code for this. Thanks to everyone! 回答1: if 'MICHAEL89' in (name.upper() for name in USERNAMES): ... Alternatively: if 'MICHAEL89' in map(str.upper, USERNAMES): ... Or, yes, you can make a custom method. 回答2: I would make a wrapper so you can be non-invasive. Minimally