Before using the sum function to summarize the list, we can consider using the map to try to cast all values to integer type firstly.
sum
map
integer
For example, the sample codes are as follows:
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "10"] sum_numbers = sum(map(int, numbers)) print(sum_numbers)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Before using the
sum
function to summarize the list, we can consider using themap
to try to cast all values tointeger
type firstly.For example, the sample codes are as follows: