The Sieve of Eratosthenes is a well known algorithm for finding primes. Typically, it is performed on a bounded set of N numbers to yield all primes less than N however with a few compromises, it is possible to make an infinite generator.
There is a solution floating around the code-scape using generator expressions which (on top of choking with python’s recursion depth) doesn’t properly follow the algorithm. This is the fake sieve:
Django Rest Framework provides a fast way to build APIs, expressing them as a set of serializers and views. I recently ran into a case where I wanted user-specific data to be included when a user is authenticated, but default to the generic serializer in all other cases.
/api/v1/items/2 (anonymous) 1 2 3 4 5 { "name": "Cannonball", "item_id": 2, "store_price": 5 } /api/v1/items/2 (authenticated) 1 2 3 4 5 6 { "name": "Cannonball", "item_id": 2, "store_price": 5, "favorited": true } This lead to two separate but similar serializers, only differing with the inclusion of the favorited field.