[Tutor] Re: reverse a number (was no subject)

Sean 'Shaleh' Perry shalehperry@attbi.com
Thu, 22 Aug 2002 09:21:00 -0700


On Thursday 22 August 2002 09:05 am, Christopher Smith wrote:
> ># There's probably a more clever way to do this part.
>
> How about converting the number to a list and then reversing the elemen=
ts
> now:
>
> =09m=3Dlist(str(int(number)))
> =09m.reverse()
> =09numString=3D''.join(m) #this is your reversed number as a string
>

or the old school C way (-:

>>> l =3D []
>>> n =3D 321
>>> while n:
=2E..   l.append(n % 10)
=2E..   n /=3D 10
=2E..=20
>>> l
[1, 2, 3]