Re: loop over list and process into groups

2010-03-05 Thread mk
lbolla wrote: It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk -- http://mail.p

Re: loop over list and process into groups

2010-03-05 Thread mk
nn wrote: Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread lbolla
On Mar 5, 1:26 pm, mk wrote: > 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 co

Re: loop over list and process into groups

2010-03-05 Thread nn
mk wrote: > 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: > >

Re: loop over list and process into groups

2010-03-05 Thread mk
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

Re: loop over list and process into groups

2010-03-05 Thread Paul Rubin
lbolla writes: > for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') This is the nicest solution, I think. Mine was more cumbersome. -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-04 Thread Chris Colbert
Man, deja-vu, I could have sworn I read this thread months ago... On Thu, Mar 4, 2010 at 2:18 PM, nn wrote: > > > lbolla wrote: > > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > > [ {'vlan_or_intf': 'VLAN2021'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_o

Re: loop over list and process into groups

2010-03-04 Thread nn
lbolla wrote: > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > [ {'vlan_or_intf': 'VLAN2021'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Po1'}, > >  {'vlan_or_intf': 'Po306'}, > >  {'vlan_or_intf': 'VLAN2022'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Gi7/33'}, >

Re: loop over list and process into groups

2010-03-04 Thread lbolla
On Mar 4, 3:57 pm, Sneaky Wombat wrote: > [ {'vlan_or_intf': 'VLAN2021'}, >  {'vlan_or_intf': 'Interface'}, >  {'vlan_or_intf': 'Po1'}, >  {'vlan_or_intf': 'Po306'}, >  {'vlan_or_intf': 'VLAN2022'}, >  {'vlan_or_intf': 'Interface'}, >  {'vlan_or_intf': 'Gi7/33'}, >  {'vlan_or_intf': 'Po1'}, >  {'v

Re: loop over list and process into groups

2010-03-04 Thread Sneaky Wombat
On Mar 4, 10:55 am, mk wrote: > Sneaky Wombat wrote: > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, > > regexes are overkill in this case I think. > > > [ 'VLAN4065', > >  'Interface', >

Re: loop over list and process into groups

2010-03-04 Thread mk
Sneaky Wombat wrote: I was going to write a def to loop through and look for certain pre- compiled regexs, and then put them in a new dictionary and append to a list, regexes are overkill in this case I think. [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Int

loop over list and process into groups

2010-03-04 Thread Sneaky Wombat
[ {'vlan_or_intf': 'VLAN2021'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2022'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi7/33'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2051'}, {'v