[Chicago] Fun with Prime Numbers and the Filter command.
Lewit, Douglas
d-lewit at neiu.edu
Sat Oct 31 23:05:48 EDT 2015
*Happy Halloween ChiPy!*
*I was messing around with a program to find prime numbers up to a
user-entered upper limit. To that end I employed the "filter" command in
the spirit of functional programming. The function I passed to the filter
command was my named function, "primeFunc", which contains and if-elif-else
structure. I tried passing an unnamed (i.e. anonymous) function to the
filter command, but noticed that if the anonymous function (declared as a
lambda expression) contains an if-elif-else structure, then Python returns
an error. So here's my question for anyone who may have a solution. Is
there a way to pass to filter a lambda expression or any other type of
anonymous function that contains various conditional expressions? Is there
a way? What I did works quite nicely of course, but.... it would be nice
to do the same thing with an unnamed or anonymous function rather than
using a previously programmer-defined (or named) function.*
*Thanks and Happy Halloween!!! ( Or Happy Samhain, for those interested in
black cats, pentagrams, and midnight rituals under the light of the full
moon! )*
*Spooky regards,*
*Douglas Lewit*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20151031/d5417e2b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindNPrimes.py
Type: text/x-python
Size: 1101 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20151031/d5417e2b/attachment.py>
More information about the Chicago
mailing list