Re: [Tutor] build list of non-empty variables

2008-07-10 Thread Tim Golden
Alan Gauld wrote: "Tim Golden" <[EMAIL PROTECTED]> wrote In fact I guess you could say that the new definition of a list comprehension is [ generator expression] Well, not if sure if you meant that literally No I meant in syntactic terms. I imagined that that was what you meant. I think

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread John Fouhy
On 10/07/2008, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Wed, Jul 9, 2008 at 9:38 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > > Is the generator expression grammar right? How do I parse, e.g., > > '(x+1 for x in range(10))'? Seems like there's nothing there for > > 'range(10)'. Like it shou

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Kent Johnson
On Wed, Jul 9, 2008 at 9:38 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > On 10/07/2008, Kent Johnson <[EMAIL PROTECTED]> wrote: >> The actual formal syntax definitions for the two are slightly different: >> http://docs.python.org/ref/lists.html >> http://docs.python.org/ref/genexpr.html > Is the

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread John Fouhy
On 10/07/2008, Kent Johnson <[EMAIL PROTECTED]> wrote: > The actual formal syntax definitions for the two are slightly different: > http://docs.python.org/ref/lists.html > http://docs.python.org/ref/genexpr.html > > Presumably this means there is something that is syntactically allowed > in on

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Kent Johnson
On Wed, Jul 9, 2008 at 8:17 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > No I meant in syntactic terms. > We usually define an LC as > > [ expr for vars in sequence if expr ] > > or somesuch imprecise gobbledy gook ;-). > > Now we can define the generator expr (syntax) as > > expr for vars in

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Alan Gauld
"Tim Golden" <[EMAIL PROTECTED]> wrote In fact I guess you could say that the new definition of a list comprehension is [ generator expression] Well, not if sure if you meant that literally No I meant in syntactic terms. We usually define an LC as [ expr for vars in sequence if expr ] o

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Tim Golden
Alan Gauld wrote: In fact I guess you could say that the new definition of a list comprehension is [ generator expression] Well, not if sure if you meant that literally, but it's certainly not: that would be a list whose one item was a generator expression: squares = (x * x for x in range (1

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Alan Gauld
"Don Jennings" <[EMAIL PROTECTED]> wrote return ';'.join(x for x in l if x) Ah! A list comprehension. Not at that point in the learning python book, Not quite, I believe its called a generator expression. Its like a list comprehension but without the [] around it. In fact I guess you coul

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Don Jennings
Ah! A list comprehension. Not at that point in the learning python book, yet, but I will be soon. Thanks! Don On Tue, Jul 8, 2008 at 9:34 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Tue, Jul 8, 2008 at 6:35 PM, Don Jennings <[EMAIL PROTECTED]> wrote: > > > def __unicode__(self): > >

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread John Fouhy
On 09/07/2008, bob gailer <[EMAIL PROTECTED]> wrote: > or just [ x for x in LIST if x ] or filter(None, LIST). But that's a bit obscure. (fractionally faster, though, according to my brief experiment with timeit) -- John. ___ Tutor maillist - Tuto

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 6:35 PM, Don Jennings <[EMAIL PROTECTED]> wrote: > def __unicode__(self): > l=[self.first_name, self.last_name, self.email, self.phone] > res=[] > > for x in l: > if x != '': > res.append(x) > > return ';'.join(

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
("Duh! Code would be good," says newbie to himself.) Here's an example from django which I am using, but I asked on this list since it seems more related to python than the web framework: class Contact(models.Model): first_name = models.CharField(max_length=30, blank=True) last_name = mod

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread bob gailer
Monika Jisswel wrote: list comprehention : [ x for x in LIST if x != '' ] or just [ x for x in LIST if x ] -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Monika Jisswel
list comprehention : [ x for x in LIST if x != '' ] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 9:14 AM, Don Jennings <[EMAIL PROTECTED]> wrote: > Hi, folks. > > From within a class, I want to return a string with data from non-empty > variables in a class. > > I could create a list of all the variables and then iterate over them, > dropping the ones which are empty, th

[Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
Hi, folks. >From within a class, I want to return a string with data from non-empty variables in a class. I could create a list of all the variables and then iterate over them, dropping the ones which are empty, then join() and return them; however, I am guessing there is another way to get that