[Tutor] List comprehensions

Kent Johnson kent37 at tds.net
Thu Jan 13 00:48:39 CET 2005


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


More information about the Tutor mailing list