Sneaky Wombat wrote: > [ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] Hey, I just invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) for x in alist if x != 'Interface'] No need to use a nuke like itertools to kill a fly. ;-) Regards, mk
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4