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 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 alternatives are intere

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 obj

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

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? > >

Re: Kindly show me a better way to do it

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 14:06:33 -0700, Oltmans wrote: > On May 9, 1:53 am, superpollo 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. Don't use t

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 d

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 wrote: > On Sat, May 8, 2010 at 4:09 PM, Günther Dietrich > wrote: > [snip] > > Too simple? > > No, not at all. I really only intended to p

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 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 Günther Dietrich
Tycho Andersen wrote: >On Sat, May 8, 2010 at 3:41 PM, Oltmans 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 wond

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 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 and here: http://tin

Re: Kindly show me a better way to do it

2010-05-08 Thread Oltmans
On May 9, 1:53 am, superpollo 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 Tycho Andersen
On Sat, May 8, 2010 at 3:41 PM, Oltmans 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 shorter, more el

Re: Kindly show me a better way to do it

2010-05-08 Thread Alain Ketterlin
Oltmans 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 list. > but I wa

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 Chris Rebert
On Sat, May 8, 2010 at 1:41 PM, Oltmans 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 shorter, more el

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 s

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? -- http://mail.python.org/mailman/listinfo/