Reverse Iteration Through Integers
python at mrabarnett.plus.com
Mon Oct 19 00:15:25 CEST 2009
Benjamin Middaugh wrote:
> I'm trying to make an integer that is the reverse of an existing integer
> such that 169 becomes 961. I guess I don't know enough yet to figure out
> how to do this without a ton of awkward-looking code. I've tried for
> loops without much success. I guess I need a good way of figuring out
> the length of the input integer so my loop can iterate that many times
> to reverse the number, but I keep getting errors that say "TypeError:
> 'Int' object is not iterable".
> Any help would be much appreciated,
You need to remember that you're not actually trying to reverse an
integer (does that actually make sense?), but the digits when it's
represented as a string (and in decimal).
More information about the Python-list