How can I search a range of versions? How can I have a integer representing a semantic version?

Looking for a way to convert semantic version to integer, I found an answer in Stack Overflow, which I think is the correct one… although it was not marked as being so.

Here is shown as a Python function:

def semantic_to_int(version):
    """
    Convert semantic version to integer, in a way that
    new version have always higher numbers.
    """
    # "5.1.13"
    l = [int(x, 10) for x in version.split('.')]
    # List created from string [5, 1, 13]
    l.reverse()
    # List reversed [13, 1, 5]
    version = sum(x * (100 ** i) for i, x in enumerate(l))
    # Use 'enumerate' to get a tuple with position/index of the list
    # and its value. Multiply position/index by the number: 
    # [13, 100, 50000]
    # Add up all numbers:
    # 50113
    return version

Keep reading