Python, convert an integer into an index?

MRAB python at mrabarnett.plus.com
Thu Sep 24 15:30:22 CEST 2015


On 2015-09-23 10:01, Anssi Saari wrote:
> Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:
>
>> On Wed, 23 Sep 2015 00:21:22 +0200, Laura Creighton <lac at openend.se>
>> declaimed the following:
>>
>>
>>>
>>>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))
>>>
>>
>> 	Rather wordy... <G>
>>
>>>>> [int(i) for i in str(1234523)]
>> [1, 2, 3, 4, 5, 2, 3]
>
> I'm suprised. Why not just:
>
> list(str(results))
>
> In other words, is there something else the list constructor should do
> with a string other than convert it to a list?
>
The OP wanted the result to be a list of ints, not a list of strings.



More information about the Python-list mailing list