List of digits from a number (python)

LLDavid Posted messages 53 Status Membre -  
LLDavid Posted messages 53 Status Membre -
Hello,

I work with Python
I want to create a list of digits from a number
example: 35482345965 should give l=[3,5,4,8,2,3,4,5,9,6,5]

Could someone give me the code for that? Thanks a lot.

2 réponses

heyquem Posted messages 808 Status Membre 131
 
Hello,

- with a list comprehension:

 x = 35482345965 print [int(c) for c in str(x)]


- in a functional programming style:

x = 35482345965 print map(int,str(x))


- to obtain the digits in a tuple, immutable = less memory usage:

x = 35482345965 print tuple(int(c) for c in str(x))
22