[Tutor] build list of non-empty variables
dfjennings at gmail.com
Wed Jul 9 04:43:32 CEST 2008
Ah! A list comprehension. Not at that point in the learning python book,
yet, but I will be soon. Thanks!
On Tue, Jul 8, 2008 at 9:34 PM, Kent Johnson <kent37 at tds.net> wrote:
> On Tue, Jul 8, 2008 at 6:35 PM, Don Jennings <dfjennings at gmail.com> 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(res)
> return ';'.join(x for x in l if x)
> will work.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor