How to count possibilities in python lists
Question: Given a list like this:

    
    
    num = [1, 2, 3, 4, 5]
    

There are 10 three-element combinations:

    
    
    [123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
    

How can I generate this list?


Answer: Use
[itertools.combinations](http://docs.python.org/library/itertools.html#itertools.combinations):

    
    
    import itertools
    
    num = [1, 2, 3, 4, 5]
    combinations = []
    for combination in itertools.combinations(num, 3):
        combinations.append(int("".join(str(i) for i in combination)))
    # => [123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
    print len(combinations)
    # => 10
    

**Edit**

You can skip int(), join(), and str() if you are only interested in the number
of combinations. itertools.combinations() gives you tuples that may be good
enough.

