Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My favorite unpacking snippet is rotating a matrix

>>> matrix = [(1,2,3),(4,5,6),(7,8,9)]

>>> list(zip(*matrix))

[(1, 4, 7), (2, 5, 8), (3, 6, 9)]

Not as readable as a real maths library, but pretty cool and educational.

Think I came across it in Python in a nut shell, by Alex Martelli

Edit: formatting





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: