A Combinations of Items in Given List

Posted by mecablaze on Stack Overflow See other posts from Stack Overflow or by mecablaze
Published on 2010-04-06T20:55:40Z Indexed on 2010/04/06 21:03 UTC
Read the original article Hit count: 213

Filed under:
|
|

Hello stackoverflow,

I'm currently in Python land. This is what I need to do. I have already looked into the itertools library but it seems to only do permutations.

I want to take an input list, like ['yahoo', 'wikipedia', 'freebase'] and generate every unique combination of one item with zero or more other items...

['yahoo', 'wikipedia', 'freebase']
['yahoo', 'wikipedia']
['yahoo', 'freebase']
['wikipedia', 'freebase']
['yahoo']
['freebase']
['wikipedia']

A few notes. Order does not matter and I am trying to design the method to take a list of any size. Also, is there a name for this kind of combination?

Thanks for your help!

© Stack Overflow or respective owner

Related posts about python

Related posts about permutation