Python | Functions | Question 7
What is the output of the following program :
import resentence = 'horses are fast'regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')matched = re.search(regex, sentence)print(matched.groupdict()) |
(A) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(B) (‘horses’, ‘are’, ‘fast’)
(C) ‘horses are fast’
(D) ‘are’
Answer: (A)
Explanation: This function returns a dictionary that contains all the matches.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.



