Created
April 10, 2017 15:51
-
-
Save rupalbarman/a4becdb5ffb3e7f0ecf17a8940816db1 to your computer and use it in GitHub Desktop.
Collections of python snippets (Matrix rotation, Prime Numbers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import itertools | |
| def pretty(a): | |
| for i in a: | |
| print(i) | |
| print() | |
| original= [[1,2], [3,4]] | |
| pretty(original) | |
| pretty(original[::-1]) | |
| rotated = list(zip(*original[::-1])) #clockwise | |
| rotated_ccw = list(zip(*original))[::-1] #counter clockwise | |
| pretty(rotated) | |
| pretty(rotated_ccw) | |
| primes2upto = lambda limit: itertools.chain([2], (p for p in range(3, limit, 2) if all(p % d != 0 for d in range(3, int(p**.5)+1, 2)))) | |
| print(list(primes2upto(10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment