![Python-courses-python-exercises-games-Python-courses-](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 50
Write a python program as a function which takes a string s as a parameter and returns the list of numeric characters contained in the string s. Example if s = 'Python 3.0, released in 2008, and completely revised in 2020' the function returns the list: [3, 0, 2, 0, 0, 8, 2, 0, 2, 0].
Solution
def extractNumbers(s):
# initializing extracted list numbers
L = []
for x in s:
if x.isnumeric():
x = int(x)
L.append(x)
return L
s = 'Python 3.0, released in 2008, and completely revised in 2020'
print(extractNumbers(s))
# The output is : [3, 0, 2, 0, 0, 8, 2, 0, 2, 0]
Younes Derfoufi
my-courses.net
my-courses.net