def merge(line):
    """
    Helper function that merges a single row or column in 2048.
    """
    n_elements = len(line)
    # Remove 0 entries and slide to the left
    line = [value for value in line if value != 0]
    index = 0
    # Iterate while there are possible pairs
    while index < len(line)-1:
        # If a pair is found, merge
        # and remove second element
        if line[index] == line[index+1]:
            line[index] *= 2
            line.pop(index+1)
        # Move on to next item
        index += 1
    # Fill the merged line with 0s so it has the
    # same number of elements than the original
    line += [0]*(n_elements-len(line))
    return line