In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 7th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #08 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
Petyr "Littlefinger" Baelish, known for his cunning and sharp mind, has intercepted several secret messages containing a mix of words and numbers. To decode potential hidden information, he wants to extract all integer numerical values embedded within these texts. The numbers could be related to important dates, coordinates, or quantities. Littlefinger needs to compile these numbers into a list for his secretive analysis.
Write a function extract_numbers(text) that given a string text returns a list of all integer values present in the text, in the order in which they appear. An integer is any sequence of digits surounded by non-integers.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |text| ≤ 200 | length of text |
Example Function Calls | Example Output |
print(extract_numbers("104 soldiers, 50 horses and 3 catapults!")) print(extract_numbers("the 7 kingdoms and the 5 stark brothers")) print(extract_numbers("zz23yy42tt678pp81")) |
[104, 50, 3] [7, 5] [23, 42, 678, 81] |