Skip to content

Non Equal Comparison

Sourcery refactoring id: non-equal-comparison

Description

Simplify comparison of non equal values

Before

def compare(a: int, b: int):
    if a < b:
        return True
    elif a > b:
        return False

After

def compare(a: int, b: int):
    if a != b:
        return a < b

Explanation

If we are comparing two numbers and returning only if they are non equal we can simplifiy the form of this expression.

Removing an if statement and merging two comparisons makes the code shorter and easier to read.