使用过滤器和映射使用 python 查找扩展名为 .txt 和 .py 的目录中的所有文件

Ang*_*Lee 1 python tuples map filter

如何使用过滤器和映射函数在以 Python结尾.txt.py以 Python结尾的目录中查找文件?

mgi*_*son 5

os.listdir将为您提供文件列表。然后你只需要编写一个函数返回True时,文件名的endsWith.py.txt

filter(lambda x: x.endswith(('.txt','.py')), os.listdir(os.curdir))
Run Code Online (Sandbox Code Playgroud)

……真不知道怎么融入map进去……