mercredi 30 août 2017

A nice way to check these conditions

I have this piece of code which checks conditions:

def is_important(data_row):
    if data_row.get('important', None):
        return True
    add_data = get_additional_data(data_row)
    for word in NEGATIVE_WORDS:
        if word in add_data.lower():
            return False
    for word in POSITIVE_WORDS:
        if word in add_data:
            return True
    return False

This is quite hard to follow (in my opinion) so is there a nice (shorter) way to write this? Could I for example merge the two for loops? Or will this increase search time.

Aucun commentaire:

Enregistrer un commentaire