Python 3 computation for
N=123456789
sum(map(int,str(N))            ---> 45
Julia 0.6.2 computation for
N = 123456789
sum([Int(ch) for ch in "$N"])  ---> 477
N = 123456789
sum(map(Int, collect("$N")))  --->  477
Why is this?
Because the python equivalent to your Julia-Statement would be
N=123456789
print( sum(map(ord,str(N))))
Output:
477
It is summing up the ascii-ord-value of '1'+'2'+...'9' - not converting each char of the string into an int and then summing up the ints.
This is not the same:
N=123456789
sum(map(int,str(N))
it converts the long int into a string, feeds each charachter into int() which converts '1' back to 1 (not to ord('1')) and then adds the numbers to 45
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With