Changed up the prime generator function to have a limit (also set a default limit): then used that limit in the call of the generator into a list: so no longer need itertools and islice. it’s better to save a list of previously encountered primes, but with one line of code, i couldn’t figure out a way to initialize and populate a list of primes to check against. I hacked it a bit and added a value limit for the prime number check, so that you can check the prime numbers up to X. this (inefficiently) checks against all odd numbers up to the square root. to complex programs like Fibonacci series, Prime Numbers. This is roughly equivalent to the below code. than 100 programs, covering beginner level programs like Hello World, Sum of Two numbers, etc. (oh, and these solutions work for negatives, zero, and one, as well-returning an empty list) def one_line_primes(n):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |