May-10-2018, 04:27 AM
Hi,
I am in Need of a little help. I wish to search within a text file and retrieve into another text file. The numbers and the words that appear after the numbers.
for example:
We have 40 white candies, 24 green ones, 12 red ones, 24 yellow ones and 20 blue ones.
40 white
24 green
12 red
24 yellow
20 blue
I managed to isolate the numbers - but I have confounded myself on how to grab the next word after the number.
['40', '24', '12', '24', '20']
I am in Need of a little help. I wish to search within a text file and retrieve into another text file. The numbers and the words that appear after the numbers.
for example:
We have 40 white candies, 24 green ones, 12 red ones, 24 yellow ones and 20 blue ones.
40 white
24 green
12 red
24 yellow
20 blue
I managed to isolate the numbers - but I have confounded myself on how to grab the next word after the number.
# Import the regular expression module import re # Find the numeric values: matches matches = re.findall('\d+', 'We have 40 white candies, 24 green ones, 12 red ones, 24 yellow ones and 20 blue ones.') # Print the matches print(matches)RESULT
['40', '24', '12', '24', '20']