Skip to content

Commit c634280

Browse files
RegEx question_ 6
1 parent 89bfae2 commit c634280

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

RegEx/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,25 @@ Answer: b
103103
Explanation: It will look for the pattern at any position in the string.
104104
```
105105
* * *
106+
107+
## Question_6: What is the output of the following? ##
108+
Question:
109+
```python
110+
sentence = 'horses are fast'
111+
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
112+
matched = re.search(regex, sentence)
113+
print(matched.groupdict())
114+
```
115+
s
116+
```python
117+
a) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
118+
b) (‘horses’, ‘are’, ‘fast’)
119+
c) ‘horses are fast’
120+
d) ‘are’
121+
```
122+
Answer:
123+
```python
124+
Answer: a
125+
Explanation: This function returns a dictionary that contains all the matches.
126+
```
127+
* * *

0 commit comments

Comments
 (0)