import random


def crossover(dna1, dna2, dna_size):
    """
    Slices both dna1 and dna2 into two parts at a random index within their
    length and merges them. Both keep their initial sublist up to the crossover
    index, but their ends are swapped.
    """
    pos = int(random.random() * dna_size)
    return (dna1[:pos] + dna2[pos:], dna2[:pos] + dna1[pos:])