[PYTHON] List memo writing part 2

Continuation of http://qiita.com/items/a8a46173c53830f7d465

Remove unnecessary elements

>>> fa = ["a", "b", None, "c", "e", None, None, None, "d"]
>>> [i for i in fa if i]
['a', 'b', 'c', 'e', 'd']

Get a list of files with the specified extension under a specific directory

>>> #Under the working directory`.eml`Get a list of files with the extension
>>> for root, dirs, files in os.walk(os.path.abspath(".")):
...     buff += [os.path.join(root, fname) for fname in files if os.path.splitext(os.path.join(root,fname))[1] == '.eml']
... 
>>> buff
['/path/to/1.eml', '/path/to/2.eml']

Recommended Posts

List memo writing part 2
List operation memo writing
[For memo] Linux Part 2
Python3 List / dictionary memo
[Memo] Python3 list sort
Python basic memo --Part 2
HTML / CSS memo writing
FastAPI Tutorial Memo Part 1
Python basic memo --Part 1
Pycharm setting memo writing
Android HCE Survey Memo (Part 2)
Linux standard textbook memo 1 part 2
Python Basic Grammar Memo (Part 1)
Linux standard textbook memo part 6
[For memo] Linux Part 1 vi editor
FastAPI Tutorial Memo Part 3 Query Parameters
FastAPI Tutorial Memo Part 2 Path Parameters
Mastodon Bot Creation Memo: Part 4 Summary
Python numbers, strings, list types (Python learning memo ①)
Memo about Sphinx Part 1 (Creating a project)
"Deep Learning from scratch" Self-study memo (Part 12) Deep learning