primes = [2,3,5,7..] (prime numbers)
map(lambda x:print(x),primes)
It does not print anything.
Why is that?
I’ve tried
sys.stdout.write(x)
too, but doesn’t work either.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
lambda x: print(x)is a syntax error in Python < 3, I’m assuming Python 3. That meansmapreturns a generator, meaning to get map to actually call the function on every element of a list, you need to iterate through the resultant generator.Fortunately, this can be done easily:
Oh, and you can get rid of the lambda too, if you like:
But, at that point you are better off with letting print handle it:
NOTE: I said earlier that
'\n'.joinwould be a good idea. That is only true for a list of str’s.