If I want to find the sum of the digits of a number, i.e.:
- Input: 932
- Output: 14, which is (9 + 3 + 2)
What is the fastest way of doing this?
I instinctively did:
sum(int(digit) for digit in str(number))
and I found this online:
sum(map(int, str(number)))
Which is best to use for speed, and are there any other methods which are even faster?