[Tutor] Re: reverse a number (was no subject)
Lance E Sloan
lsloan@umich.edu
Fri, 23 Aug 2002 09:36:08 -0400
--On Thursday, August 22, 2002 11:05 AM -0500 Christopher Smith
<csmith@blakeschool.org> wrote:
>-- Lance E Sloan <lsloan@umich.edu> wrote:
>># There's probably a more clever way to do this part.
>> newnumString = ''
>> for n in numString:
>> newnumString = n + newnumString
>
> How about converting the number to a list and then reversing the elements
> now:
>
> m=list(str(int(number)))
> m.reverse()
> numString=''.join(m) #this is your reversed number as a string
Thanks! That's exactly what I was trying to think of. I thought it was a
string method.
--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting. Specializing in Python & Perl CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"