how to shuffle a list correctly in python
Question: I have this code that shuffles a list. I first split it into two lists because
I have a interleave function that interleaves 2 lists:

    
    
    def shuffle(xs, n=1):
        il=list()
        if len(xs)%2==0:
            stop=int(len(xs)//2)
            a=xs[:stop]
            b=xs[stop:]
            print(a)
            print(b)
        else:
            stop=int(len(xs)//2)
            a=xs[:stop]
            b=xs[stop:]
            print(a)
            print(b)
        if n>0:
            for i in range(n):
                shuffle=interleave(a,b)
        else:
            return 
        return shuffle
    

and when I test it:

    
    
    >>> shuffle([1,2,3,4,5,6,7],1)
    [1, 2, 3]
    [4, 5, 6, 7]
    1
    [7]
    [7, 4]
    [1, 4, 2, 5, 3, 6, 7, 4]
    

What is 4 in the list twice and why is it printing 1, [7], 7,4]??

EDIT:

    
    
    def interleave(xs,ys):
        a=xs
        b=ys
        minlength=[len(a),len(b)]
        extralist= list()
        interleave= list()
        for i in range((minval(minlength))):
            pair=a[i],b[i]
            interleave.append(pair)
            flat=flatten(interleave)
            c=a+b
        if len(b)>len(a):
            remainder=len(b)-len(a)
            for j in range(remainder,-1,-1):
                extra=b[-j]
                extralist.append(extra)
        if len(a)>len(b):
            remainder=len(a)-len(b)
            for j in range(remainder,-1,-1):
                extra=a[-j]
                extralist.append(extra)
        del extralist[-1]
        final=flat+extralist
        return final
    


Answer: Why not just use the standard library?

    
    
    >>> from random import shuffle
    >>> l = list(range(1,20))                                                                                                                                                                                                                       
    >>> l
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    >>> shuffle(l)                                                                                                                                                                                                                                  
    >>> l
    [17, 15, 9, 13, 19, 7, 10, 18, 5, 1, 12, 3, 2, 16, 4, 14, 8, 6, 11]
    >>> 
    

