What lines or code constructs are causing you to scratch your head? (No, not gonna comment every single line.)
As a general suggestion you should probably read up on Python, rather than stare at some sample code. Because the latter is actually the long way, not the short-cut you were looking for.
Welcome to the forums, your journey into Python has begun!