Python, convert an integer into an index?
python at mrabarnett.plus.com
Wed Sep 23 01:27:03 CEST 2015
On 2015-09-22 23:21, Laura Creighton 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)
>>results = [1, 2, 3, 4, 5, 2, 3] #(INDEX)
>>Somehow I see ways to convert index to list to int, but not back again.
> You need to convert your results into a string first.
> for digit in str(result_int):
> 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
A shorter way using strings:
>>> results = 134523
>>> list(map(int, str(results)))
[1, 3, 4, 5, 2, 3]
More information about the Python-list