mercredi 28 juillet 2021

How can I summarize splits and regex into less lines in Python?

if len(re.findall('\\bim\\b', message.lower())) > 0:
    new_list = message.lower()
    x = new_list.split("im ")
elif len(re.findall("\\bi'm\\b", message.lower())) > 0:
    new_list = message.lower()
    x = new_list.split("i'm ")

I found this code of mine from ages ago and I'm awful in Regex, I know that you can use the (a|b) filter probably though, it's obviously very inefficient and I'm sure it can be tidied up a lot.

Aucun commentaire:

Enregistrer un commentaire