Apr-11-2020, 01:15 AM
(This post was last modified: Apr-11-2020, 01:16 AM by ClassicalSoul.)
Surely there has got to be a better way of doing this?
>>> d = dict(enumerate(list('abcde'))) >>> INPUT = [[(0, 1, 2), (3, 4)], [(0, 1, 3), (2, 4)], [(0, 1, 4), (2, 3)], [(0, 2, 3), (1, 4)], [(0, 2, 4), (1, 3)], [(0, 3, 4), (1, 2)], [(1, 2, 3), (0, 4)], [(1, 2, 4), (0, 3)], [(1, 3, 4), (0, 2)], [(2, 3, 4), (0, 1)]] >>> list(map(lambda grouping: tuple(map(lambda group: tuple(map(lambda id_: d[id_], group)), grouping)), INPUT))
Output:[(('a', 'b', 'c'), ('d', 'e')), (('a', 'b', 'd'), ('c', 'e')), (('a', 'b', 'e'), ('c', 'd')), (('a', 'c', 'd'), ('b', 'e')), (('a', 'c', 'e'), ('b', 'd')), (('a', 'd', 'e'), ('b', 'c')), (('b', 'c', 'd'), ('a', 'e')), (('b', 'c', 'e'), ('a', 'd')), (('b', 'd', 'e'), ('a', 'c')), (('c', 'd', 'e'), ('a', 'b'))]