coding utf-8 def load_struct return l1e1 l2e for in range l3e for in r

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
def load_struct():
return [ ['l1e1'],
['l2e%d'%(i+1,) for i in range(4)],
['l3e%d'%(i+1,) for i in range(4)],
]
def pairs(l):
return ((x,y) for i,x in enumerate(l) for y in l[i+1:])
def _traverse(chain, levels):
if levels == []:
raise StopIteration
cur_level = levels[0]
if len(cur_level) > 1:
for pair in pairs(cur_level):
yield chain + (pair,)
for el in cur_level:
for x in _traverse(chain + (el,), levels[1:]):
yield x
def traverse(struct):
return _traverse((), struct)