New submission from Matthew Drago <mattdra...@gmail.com>:
Say for example i want to apply a regex on a list of strings. Using list comprehension as such results in the group method not being found. ``` name_regex = compile(r'\[\"([a-zA-Z\s]*)\"{1}') named_entities = [name_regex.match(entity.trigger).group(1) for entity in entities[0]] ``` This unexpected behavior can also be observed when implementing this using a map. ``` list(map(lambda x: name_regex.search(x.trigger).group(), entities[0])) ``` However using the traditional for loop implementation the group method is resolved. ``` named_entities = [] for entity in entities[0]: named_entities.append(name_regex.match(entity.trigger).group(1)) ``` ---------- components: Regular Expressions messages: 336936 nosy: Matthew Drago, ezio.melotti, mrabarnett priority: normal severity: normal status: open title: Regex search behaves differently in list comprehension type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36158> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com