Python: Separate and print the numbers of a given string
Write a Python program to separate and print the numbers in a given string.
Sample Solution:
Python Code:
import re
# Sample string.
text = "Ten 10, Twenty 20, Thirty 30"
result = re.split("\D+", text)
# Print results.
for element in result:
print(element)
Sample Output:
10 20 30
Pictorial Presentation:
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to match if two words from a list of words starting with letter 'P'.
Next: Write a Python program to find all words starting with 'a' or 'e' in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics