3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by sneekula
0

Hi!

You have to convert the integer to an iterable (e.g. a string), then split it into a list, then convert the elements of the list back to integers:

x = 12345
newx = [int(i) for i in list(str(x))]

Regards, mawe

0

If you wanted to use the digits of an integer, you could convert to a string like mawe suggested and then use the indexed string elements ...

x = 12345
s = str(x)
print s[0]  # 1
print s[1]  # 2
print s[2]  # 3
print s[4]  # 5

print type(s[2])  # <type 'str'>

# to get an integer value use
i = int(s[2])
print i  # 3
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.