[Tutor] List comprehensions

Liam Clarke cyresse at gmail.com
Thu Jan 13 01:42:30 CET 2005


Aah, thank you both - I knew there was a way to do it.

Regards, 

Liam Clarke

PS John - another Kiwi, seems to be a lot of NZers involved in Python
& Python projects. Is  it the No. 8 wire freedom of Python? ; )

On Wed, 12 Jan 2005 18:48:39 -0500, Kent Johnson <kent37 at tds.net> wrote:
> If you mean for j to be a list of foobar(item) then use
> j=[foobar(item) for item in x]
> 
> The first part of the list comp can be any valid expression.
> 
> Kent
> 
> Liam Clarke wrote:
> > Hi,
> >
> > Am I able to achieve something like this -
> >
> > def foobar();
> > # stuff
> > return
> >
> > x=[1,....1000]
> >
> > for j=foobar(item) for item in x:
> >
> > As a comprehension, if you get what I mean... Can I build a for loop
> > with a function in  for x in x part?
> >
> > Ack. Having difficulty summing it up properly.
> >
> >
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list