Skip to content

Instantly share code, notes, and snippets.

@kotoripiyopiyo
Created November 27, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotoripiyopiyo/ba1cf2f847d24d4f0248c7494c1fb1e3 to your computer and use it in GitHub Desktop.
Save kotoripiyopiyo/ba1cf2f847d24d4f0248c7494c1fb1e3 to your computer and use it in GitHub Desktop.
テキストファイルだけを抜き出してくるリスト内包表記
txtfile_list = [file_name for file_name in os.listdir() if re.search(r'.*.txt$', file_name)]
@kotoripiyopiyo
Copy link
Author

kotoripiyopiyo commented Nov 27, 2020

普通にforした場合

txt_regex = re.compile(r'.*.txt$')
for file_name in os.listdir():
    if txt_regex.search(file_name) is None:
        continue
    else:
        txtfile_list.append(file_name)
print(txtfile_list)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment