Sebastian Bassi wrote: > I have 2 (or more) groups of elements, and I want to get all possible > unique combinations from all of them. Is there a build-in method to do > it? > > ADictionary={"one":["A","B","C","D"],"two":["H","I"]} > > I want to have all possible combinations from "one" and "two", that is: > > AH > BI > CH > DI > AI > BH > CI > DH > > Sounds easy, but is not :) > > Oh but it is:
>>> ADictionary={"one":["A","B","C","D"],"two":["H","I"]} >>> result = set() >>> for one in ADictionary["one"]: ... for two in ADictionary["two"]: ... result.add(one + two) ... >>> result set(['CI', 'CH', 'DH', 'DI', 'AI', 'AH', 'BH', 'BI']) /W -- http://mail.python.org/mailman/listinfo/python-list