Terry J. Reedy <tjre...@udel.edu> added the comment:
I agree that from the outside is seems slightly bizarre to make an internal list to implement a function documented as returning an iterator. However, list(scandir) was added by Serhiy in #26032 with the comment that it made globbing 1.5-4 times faster. This is, of course, if one runs the iterator to completion, as is the normal use. For your presented use case, I suggest something like the following: next(f for f in scandir(path) if os.path.splitext(f)[1] == '.txt') ---------- nosy: +terry.reedy versions: -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44069> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com