Python, convert an integer into an index?

Chris Roberts thecjguy1 at gmail.com
Wed Sep 23 18:18:42 CEST 2015


Fantastic!
I started a course, but I have been having issues with
string/index/list/integer conversions and manipulations.
This variation wasn't in any of my texts or class exercises either.
Your way was both simple enough to understand and very informative!
Thanks.


On Tue, Sep 22, 2015 at 6:21 PM, Laura Creighton <lac at openend.se> wrote:

> In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes:
> >
> >
> >(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.
> >
> >Thanks,
> >crzzy1
>
> You need to convert your results into a string first.
>
> result_int=1234523
> result_list=[]
>
> for digit in str(result_int):
>     result_list.append(int(digit))
>
> digit will be assigned to successive 1 character long strings.  Since
> you wanted a list of integers, you have to convert it back.
>
> If you are learning python you may be interested in the tutor mailing
> list. https://mail.python.org/mailman/listinfo/tutor
>
> Laura
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150923/dcbd20f7/attachment.html>


More information about the Python-list mailing list