Skip to content

Instantly share code, notes, and snippets.

@rupalbarman
Created April 10, 2017 15:51
Show Gist options
  • Select an option

  • Save rupalbarman/a4becdb5ffb3e7f0ecf17a8940816db1 to your computer and use it in GitHub Desktop.

Select an option

Save rupalbarman/a4becdb5ffb3e7f0ecf17a8940816db1 to your computer and use it in GitHub Desktop.
Collections of python snippets (Matrix rotation, Prime Numbers)
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