How to make a list view using group () method in python?

I am trying to write a little script to clean my directories. In fact, I have:

pattern = re.compile(format[i])
...
current_f.append(pattern.search(str(ls)))

and I want to use list comprehension, but when I try:

In [25]: [i for i in current_f.group(0)]

I get:

AttributeError: 'list' object has no attribute 'group'

So how to make a list comprehension using group()? Is there any other way to do what I want?

+3
source share
1 answer

Are you trying to do this ?:

[f.group(0) for f in current_f]
+7
source

Source: https://habr.com/ru/post/1704797/


All Articles