Re: [Tutor] Another list comprehension question

2007-02-27 Thread John Fouhy
On 28/02/07, Smith, Jeff <[EMAIL PROTECTED]> wrote: > I realize however that this is probably much less efficient since you > are iterating over the inner list rather than just taking it on in > whole. Well, you know what they say --- don't guess, profile :-) Morpork:~ repton$ python -m timeit -s

Re: [Tutor] Another list comprehension question

2007-02-27 Thread Smith, Jeff
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Fouhy Sent: Monday, February 26, 2007 4:00 PM To: Smith, Jeff Cc: tutor@python.org Subject: Re: [Tutor] Another list comprehension question On 27/02/07, Smith, Jeff <[EMAIL PROTECTED]> wrote:

Re: [Tutor] Another list comprehension question

2007-02-27 Thread Smith, Jeff
-Original Message- From: Bob Gailer [mailto:[EMAIL PROTECTED] Sent: Monday, February 26, 2007 3:53 PM To: Smith, Jeff Cc: tutor@python.org Subject: Re: [Tutor] Another list comprehension question >> files = list() >Or just files = [] I tend to prefer the former since it h

Re: [Tutor] Another list comprehension question

2007-02-26 Thread Bob Gailer
John Fouhy wrote: [snip] > > Or [x for k in get_clists() for x in get_clist(k)] using your original > structure. > Well I learned something! -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/t

Re: [Tutor] Another list comprehension question

2007-02-26 Thread John Fouhy
Hi Jeff, On 27/02/07, Smith, Jeff <[EMAIL PROTECTED]> wrote: > I'm probably missing something simple here but is there anyway to > accomplish the following with a list comprehension? > > def get_clists(): > return [1, 2, 3] > > def get_clist(num): > if num == 1: > return ['a', 'b',

Re: [Tutor] Another list comprehension question

2007-02-26 Thread Bob Gailer
Smith, Jeff wrote: > I'm probably missing something simple here but is there anyway to > accomplish the following with a list comprehension? > Each element created by a comprehension corresponds to an element returned by the for (if) clause. So we have to find a way for the for clause to retur

[Tutor] Another list comprehension question

2007-02-26 Thread Smith, Jeff
I'm probably missing something simple here but is there anyway to accomplish the following with a list comprehension? def get_clists(): return [1, 2, 3] def get_clist(num): if num == 1: return ['a', 'b', 'c'] if num == 2: return ['x', 'y', 'z'] if num == 3: