Skip to content

Non Equal Comparison

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: non-equal-comparison

Section titled “Sourcery refactoring id: non-equal-comparison”

Simplify comparison of non equal values

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

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.