Sum digits of numbers in a list
<p>Trying to write a function that takes a list like:</p>

<pre><code>x = [1, 13, 14, 9, 8]
</code></pre>

<p>for example and sums the digits like:</p>

<pre><code>1 + (1+3) + (1+4) + 9 + 8 = 27       
</code></pre>

<p>What I have attempted thus far:</p>

<pre><code>def sum_d(x):
    if not x:
        return 0
    else:
        return x[0] + sum_d(x[1:])
</code></pre>

<pre><code>x = [1,13,14,9,8]
number = 0
for element in x:
    my_string = str(element)
    for i in range(len(my_string)):
        number += int(my_string[i])
print(number)
</code></pre>

<p>This will do it, there might be a way to slice ints that doesn't involve converting them to strings though.</p>

python list python-3.x