ewalker at micron.com
Fri Nov 4 20:26:58 CET 2005
On Friday 04 November 2005 11:53 am, Kent Johnson wrote:
> Eric Walker wrote:
> > All,
> > Whats the construct that allows to loop through a list and perform an
> > action? you also can add a test at the end. something like myfile =
> > [print name for name in yourlist, if ...]
> It's called a list comprehension. You can see some examples here:
> It won't work with your example though - 'print' is a statement, not an
> expression, and cannot be used in a LC. You could use sys.stdout.write(name
> + '\n') instead if you like.
> Personally I think it is bad style to use a LC for its side effects; in
> those cases I prefer to write the loop out.
More information about the Tutor