List only file names that contain specific phrases in Python listdir content

Asked 2 years ago, Updated 2 years ago, 16 views

os.listdir() This is the content of the list using

Quarterly report (2017.09) Samsung Electronics' consolidated cash flow statement.csv',

Quarterly Report (2018.03) Samsung Electronics' consolidated financial position statement.csv',

Quarterly report (2018.03) Samsung Electronics' consolidated cash flow statement.csv',

Quarterly report (2018.09) Samsung Electronics' consolidated financial position statement.csv',

Quarterly report (2018.09) Samsung Electronics' consolidated cash flow statement.csv',

Quarterly Report (2019.03) Samsung Electronics' consolidated financial position statement.csv',

Quarterly report (2019.03) Samsung Electronics' consolidated cash flow statement.csv',

Quarterly report (2019.09) Samsung Electronics' consolidated financial position statement.csv',

If there is a list like this, what should I do if I want to list only the statement of financial position on the list?

python

2022-09-20 22:17

2 Answers

import os
for i in os.listdir():
    if 'something' in i:
        print(i)


2022-09-20 22:17

l = [x for x in os.listdir() if 'financial position' in x]


2022-09-20 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.