If I have an integer like x = 12345, how do I separate that into individual integers 1, 2, 3, 4, 5?
sneekula
969
Nearly a Posting Maven
Recommended Answers
Jump to PostHi!
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
All 3 Replies
mawe
6
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
sneekula
969
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.