![]() ![]() for 2 to 7? How does that result in "13"? The lambda is iterating over x in nums correct? And i is iterating over the range 2 to 7. nums = range(2, 20)Īgain, I don't understand why it ignores all primes below 11.Īgain, this makes no sense to me. Likewise, when I remove the x = i component, it returns the prime numbers from 11 to 19. When I remove the x % i component, I would expect this code to give me the numbers common to both sets, but it does not: nums = ![]() I even created a Python implementation of the Sieve of Eratosthenes, hoping that might give me some insight, but it didn't. I also don't understand why the second range is only 2 to 7. but I don't understand the role " x = i or x % i" plays in the whole thing. Primes = filter(lambda x: x = i or x % i, primes) I have been sweating over this piece of code - which returns all the primes in a list: primes = range(2, 20)
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |