[Tutor] Pythonify this code!

A.T.Hofkamp a.t.hofkamp at tue.nl
Tue Jul 14 13:25:24 CEST 2009


Dave Angel wrote:
> def separateToList(num):
>     """
>     changes an integer 0-255 into a list of ints, size exactly 3
>     """
>     return map(int, list(format(num, "03d")))

Nice!

Note that the "list" conversion is not needed; when you iterate over a string 
you automatically get each character in turn:

map(int, ("%03d" % num))


Albert


More information about the Tutor mailing list