python newbie question

Donn Cave donn at u.washington.edu
Thu Jul 19 13:05:30 EDT 2001


Quoth donmalla at yahoo.co.in:
...
| However when I try to manipulate the list , using for loop like this :
|
| [3*x for x in vec]
|
| I get a syntax error "invalid syntax"
|
| Please help me. I am using Python 1.5 on Windows 2000.

If you need this to work, you will have to upgrade to a
more current version of Python.  In 1.5 there are no list
incomprehensions, so it's either

    a = []
    for x in vec:
        a.append(3 * x)

 or
    a = map(lambda x: 3 * x, vec)

 ("lambda x: 3 * x" is an anonymous function, not otherwise very
 useful in Python;  map is generally  map(fn, seq[, ...]) where
 fn accepts 1 parameter per seq, and it's usually easier and
 more readable to define an ordinary function.  Hope "lambda"
 is the only thing Greek about this.)

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list