Python, convert an integer into an index?

Ian Kelly ian.g.kelly at gmail.com
Wed Sep 23 00:13:45 CEST 2015


On Sep 22, 2015 3:46 PM, "Chris Roberts" <thecjguy1 at gmail.com> wrote:
>
>
> (How do I make it into an index? )
> Preferably something fairly easy to understand as I am new at this.
>
> results = 134523      #(Integer)
>
> Desired:
> results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)
>
> Somehow I see ways to convert index to list to int, but not back again.

I'm not sure what you mean by "index" in this context, but do you just want
to convert the integer into a list of its digits? The simple way is to
convert it to a string, then convert each character back to an int, and put
the results into a list. More efficient way would be to strip the digits
off one at a time by dividing modulo 10.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150922/eea32c54/attachment.html>


More information about the Python-list mailing list