Python efficent non cases sensitive match? [duplicate]

In python to check if 'apple' appears in another string we do:

if 'apple' in my_str:

To check without cases sensitive I read we can do:

if 'apple' in my_str.lower():

But what if my_str is REALLY long, it's not efficent to call .lower() on it... Doesn't python support native non cases sensitive match?


Solution 1:

You can use regular expressions and re.IGNORECASE In python Case insensitive regular expression without re.compile?

import re
s = 'padding aAaA padding'
print(bool(re.findall("aaaa",s,re.IGNORECASE)))

Prints True.