Re: Kindly show me a better way to do it

2010-05-10 Thread Jean-Michel Pichavant
Oltmans wrote: On May 9, 1:53 am, superpollo ute...@esempio.net wrote: add = lambda a,b: a+b for i in reduce(add,a): print i This is very neat. Thank you. Sounds like magic to me. Can you please explain how does that work? Many thanks again. shorter nicer IMO. Those

Re: Kindly show me a better way to do it

2010-05-09 Thread Steven D'Aprano
On Sat, 08 May 2010 14:06:33 -0700, Oltmans wrote: On May 9, 1:53 am, superpollo ute...@esempio.net wrote: add = lambda a,b: a+b for i in reduce(add,a):      print i This is very neat. Thank you. Sounds like magic to me. Can you please explain how does that work? Many thanks again.

Re: Kindly show me a better way to do it

2010-05-09 Thread Steven D'Aprano
On Sun, 09 May 2010 15:17:38 +1000, Lie Ryan wrote: On 05/09/10 07:09, Günther Dietrich wrote: Why not this way? a = [[1,2,3,4], [5,6,7,8]] for i in a: for j in i: print(j) 1 2 3 4 5 6 7 8 Too simple? IMHO that's more complex due to the nested

Re: Kindly show me a better way to do it

2010-05-09 Thread Lie Ryan
On 05/09/10 19:18, Steven D'Aprano wrote: On Sun, 09 May 2010 15:17:38 +1000, Lie Ryan wrote: On 05/09/10 07:09, Günther Dietrich wrote: Why not this way? a = [[1,2,3,4], [5,6,7,8]] for i in a: for j in i: print(j) 1 2 3 4 5 6 7 8 Too simple? IMHO

Re: Kindly show me a better way to do it

2010-05-09 Thread Steven D'Aprano
On Sun, 09 May 2010 22:52:55 +1000, Lie Ryan wrote: IMHO that's more complex due to the nested loop, What's so complex about a nested loop? one more nested tab. That extra whitespaces is quite irritating. Then say you don't like it, don't try to make a subjective dislike seem objectively

Kindly show me a better way to do it

2010-05-08 Thread Oltmans
Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]: for a in i: print a but I was wondering if there is a shorter, more elegant way to do it? --

Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo
Oltmans ha scritto: Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]: for a in i: i think you used te a identifier for two meanings... print a but I was wondering if there is a

Re: Kindly show me a better way to do it

2010-05-08 Thread Chris Rebert
On Sat, May 8, 2010 at 1:41 PM, Oltmans rolf.oltm...@gmail.com wrote: Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]:        for a in i:                print a but I was wondering if there is a

Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo
superpollo ha scritto: Oltmans ha scritto: Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]: for a in i: i think you used te a identifier for two meanings... print a but I was wondering if

Re: Kindly show me a better way to do it

2010-05-08 Thread Alain Ketterlin
Oltmans rolf.oltm...@gmail.com writes: a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]: for a in i: print a I would prefer: for i in a: for v in i: print v i.e., not messing with a and avoiding an additional

Re: Kindly show me a better way to do it

2010-05-08 Thread Tycho Andersen
On Sat, May 8, 2010 at 3:41 PM, Oltmans rolf.oltm...@gmail.com wrote: Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]:        for a in i:                print a but I was wondering if there is a

Re: Kindly show me a better way to do it

2010-05-08 Thread Oltmans
On May 9, 1:53 am, superpollo ute...@esempio.net wrote: add = lambda a,b: a+b for i in reduce(add,a):      print i This is very neat. Thank you. Sounds like magic to me. Can you please explain how does that work? Many thanks again. -- http://mail.python.org/mailman/listinfo/python-list

Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo
Oltmans ha scritto: On May 9, 1:53 am, superpollo ute...@esempio.net wrote: add = lambda a,b: a+b for i in reduce(add,a): print i This is very neat. Thank you. Sounds like magic to me. Can you please explain how does that work? Many thanks again. here: http://tinyurl.com/3xp

Re: Kindly show me a better way to do it

2010-05-08 Thread Günther Dietrich
Tycho Andersen ty...@tycho.ws wrote: On Sat, May 8, 2010 at 3:41 PM, Oltmans rolf.oltm...@gmail.com wrote: Hi, I've a list that looks like following a = [ [1,2,3,4], [5,6,7,8] ] Currently, I'm iterating through it like for i in [k for k in a]:        for a in i:                print a

Re: Kindly show me a better way to do it

2010-05-08 Thread Tycho Andersen
On Sat, May 8, 2010 at 4:09 PM, Günther Dietrich gd.use...@spamfence.net wrote: [snip] Too simple? No, not at all. I really only intended to point the OP to itertools, because it does lots of useful things exactly like this one. \t -- http://mail.python.org/mailman/listinfo/python-list

Re: Kindly show me a better way to do it

2010-05-08 Thread Nathan Rice
itertools is also written in c, so if you're working with a big nested list is long it will be a lot faster. On Sat, May 8, 2010 at 5:40 PM, Tycho Andersen ty...@tycho.ws wrote: On Sat, May 8, 2010 at 4:09 PM, Günther Dietrich gd.use...@spamfence.net wrote: [snip] Too simple? No, not at

Re: Kindly show me a better way to do it

2010-05-08 Thread Lie Ryan
On 05/09/10 07:09, Günther Dietrich wrote: Why not this way? a = [[1,2,3,4], [5,6,7,8]] for i in a: for j in i: print(j) 1 2 3 4 5 6 7 8 Too simple? IMHO that's more complex due to the nested loop, though I would personally do it as: a = [