Random Output from a list - Python
Question: 
    Stores = ["alpha","bravo","charlie","delta"]
    KnownName = Stores.pop()
    KnownName2 = Stores.pop()
    KnownName3 = Stores.pop()
    print KnownName+" "+Stores.pop() 
    print KnownName2+" "+KnownName
    print KnownName3+" "+KnownName2 
    print KnownName3 
    

Output:

    
    
    delta alpha
    charlie delta
    bravo charlie
    bravo
    

So if I have a list of m1,m2,m3...mn I am trying to get random out such as
this

    
    
    m1
    m2 m3
    m4 m2
    m5
    m6 m7
    m8 m9
    m10 m8
    m11 m10
    

If you look at the outputs, a maximum of two values in a line. Only the first
value can repeat.

How can I improve my code?

    
    
    foo = ['m1', 'm2', 'm3', 'm4', 'm5','m6','m7','m8']
    foo.reverse()
    while foo:
        try:
            if random.randrange(0,2) == 0:
                print foo.pop()
            else:
                Value2 = foo.pop()
                print Value2 + " " + foo.pop()
                if random.randrange(0,2) == 0:
                    Value3 = foo.pop()
                    print Value3 + " " + Value2
                else:
                    foo.pop() + foo.pop()
        except:
            break
    


Answer: you may try this.

    
    
    from random import randint
    
    foo = ['m1', 'm2', 'm3', 'm4', 'm5','m6','m7','m8']
    while foo:
        x = randint(0, len(foo) - 1)
        y = randint(0, len(foo) - 1)
        while x == y and len(foo) > 1:
            y = randint(0, len(foo) - 1)
        if randint(0, 1) == 0 or len(foo) <= 1:
            print foo[x]
        else:
            print foo[y], foo[x]
        foo = foo[:x] + foo[x+1:]
    

