Subtract all items in a list against each other
Question: I have a list in Python that looks like this:

    
    
    myList = [(1,1),(2,2),(3,3),(4,5)]
    

And I want to subtract each item with the others, like this:

    
    
    (1,1) - (2,2)
    (1,1) - (3,3)
    (1,1) - (4,5)
    (2,2) - (3,3)
    (2,2) - (4,5)
    (3,3) - (4,5)
    

The expected result would be a list with the answers:

    
    
    [(1,1), (2,2), (3,4), (1,1), (2,3), (1,2)]
    

How can I do this? If I approach it with a `for` loop, I can maybe store the
previous item and check it against the one that I'm working with at that
moment, but it doesn't really work.


Answer: Use `itertools.combinations` with tuple unpacking to generate the pairs of
differences:

    
    
    >>> from itertools import combinations
    >>> [(y1-x1, y2-x2) for (x1, x2), (y1, y2) in combinations(myList, 2)]                    
    [(1, 1), (2, 2), (3, 4), (1, 1), (2, 3), (1, 2)]
    

