On Sun, 07 Apr 2013 04:16:27 -0700, ReviewBoard User wrote: > Hi > I am a newbie to python and am trying to write a program that does a sum > of squares of numbers whose squares are odd. For example, for x from 1 > to 100, it generates 165 as an output (sum of 1,9,25,49,81) > > Here is the code I have > print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: x*x, > xrange(10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) > > I am getting a syntax error. > Can you let me know what the error is?
Python already has told you what the error is. You should read the error message. If you don't understand it, you should copy and paste the full traceback, starting with the line "Traceback", and ask for help. But please do not expect us to *guess* what error you are seeing. I'm now going to guess. I think you are seeing this error: py> len(x) = len(y) File "<stdin>", line 1 SyntaxError: can't assign to function call In this example, I have a function call, len(x), on the left hand side of an assignment. That is illegal syntax. In your code, you also have a function call reduce(...) on the left hand side of an assignment. If the error message is not clear enough, can you suggest something that would be more understandable? Perhaps you meant to use an equality test == instead of = assignment. > I am new to Python and am also looking for good documentation on python > functions. http://www.python.org/doc/ does not provide examples of usage > of each function No, the reference material does not generally provide examples. Some people like that style, and some don't. However, many pages do have extensive examples: http://docs.python.org/2/library/string.html You should also work through a tutorial or two. Also the "Module of the week" website is very good: http://pymotw.com -- Steven -- http://mail.python.org/mailman/listinfo/python-list