Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2 

3"""Solution to chapter 7, exercise 29: sum_numbers""" 

4 

5 

6def sum_numbers(numbers): 

7 """Takes a string containing space-separated words. 

8Output is an integer, the sum of those words that can 

9be turned into integers. 

10""" 

11 return sum(int(number) 

12 for number in numbers.split() 

13 if number.isdigit())