[issue41259] Find adverbs is not correct
New submission from Rim Chatti <chattiriim@gmail.com>: re.findall(r"\w+ly", text) does not find all adverbs in a sentence, it finds words that contain ly (not ending with ly) : if text= 'andlying clearly', output: [andly, clearly] which is wrong! the right way to do this is re.findall(r'\b(\w+ly)\b',text) output= clearly! ---------- assignee: docs@python components: Documentation messages: 373406 nosy: Rim Chatti, docs@python priority: normal severity: normal status: open title: Find adverbs is not correct versions: Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Change by Rim Chatti <chattiriim@gmail.com>: ---------- title: Find adverbs is not correct -> Find adverbs is not correct on the documentation _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: Please submit a PR. The parenthesis are not needed: re.findall(r"\b\w+ly\b", text) ---------- keywords: +easy nosy: +rhettinger versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Rim Chatti <chattiriim@gmail.com> added the comment: re.findall(r"\w+ly", text) does not find all adverbs in a sentence, it finds words that contain ly (not ending with ly) : if text= 'andlying clearly', output: [andly, clearly] which is wrong! the right way to do this is re.findall(r'\b\w+ly\b',text) output= clearly! ---------- components: +Regular Expressions -Documentation keywords: +patch message_count: 2.0 -> 3.0 nosy: +ezio.melotti, mrabarnett nosy_count: 3.0 -> 5.0 pull_requests: +20569 stage: -> patch review type: -> behavior pull_request: https://github.com/python/cpython/pull/21420 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Peter Otten <__peter__@web.de> added the comment: While I don't want to start a philosical discussion -- is that really better? Finding adverbs with a regex doesn't work in the general case -- think butterfly, panoply, well -- and the example is meant to illustrate the usage of re.findall() rather than regex syntax. "finding adverbs" is just shorter and easier to understand than "finding sequences of word characters that end with "ly". ---------- nosy: +peter.otten _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: I think it's fine as-is. The real purpose of the example is show basic patterns in writing regexes. Pig-latin examples or searching for words ending in -ly make for nice beginner examples. I like the OP's modification because it teaches a general skill (the importance of \b for making sure you get whole words). We could add a link to the Natural Language Toolkit for people who are getting serious about searching for parts of speech. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
Sagnik Mazumder <sagnikmazumdar37@gmail.com> added the comment: fixed finding adverbs example in re docs ---------- message_count: 5.0 -> 6.0 nosy: +Sagnik Mazumder nosy_count: 6.0 -> 7.0 pull_requests: +20871 pull_request: https://github.com/python/cpython/pull/21728 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41259> _______________________________________
participants (4)
-
Peter Otten -
Raymond Hettinger -
Rim Chatti -
Sagnik Mazumder