Split three-digit integer to three-item list of each digit in Python -


I'm new to Python, what I have to do is, the three digit integer like 634 , And divides it, so this three-item list becomes, i.e.

points = [6, 3, 4]

Any help in this will be highly appreciated.

You can convert the number to a string, then iterate over the string, and each character Convert back to an integer:

  & gt; & Gt; & Gt; [6, 3, 4]   

Or, as F. correctly indicates below, use:

  & gt; & Gt; & Gt; Map (int, str (634)) # Python 2 [6, 3, 4]> gt; & Gt; & Gt; List (map (int, str (634)) # Python 3 [6, 3, 4]    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -