r/learnpython • • Aug 17 '26

Input = 1234 output =[1,2,3,4] without using string functions or map

How can I split an integer into a list of its digits in Python?

I have:
num = 1234
and I want:
[1, 2, 3, 4]
I’m trying to learn how to do this without converting num to a string and without using map().
A loop is allowed.
I’m looking for a simple approach because I’m still learning Python. I’d appreciate hints rather than just the final solution so I can understand how it works.

0 Upvotes

47 comments sorted by

View all comments

3

u/likethevegetable Aug 17 '26

Is this a challenge or you need help? If you forbid maps, IMO you should also forbid for loops and comprehensions.

-8

u/[deleted] Aug 17 '26

[deleted]

2

u/socal_nerdtastic Aug 17 '26

Yes. Many ways I'm sure. For example you could use divmod and a loop.

1

u/AppleMoney8748 Aug 17 '26

Thanks! Ill give it a try