serhii.net

In the middle of the desert you can say anything you want

06 Sep 2022

Python pathlib Path check if directory is empty

Was doing len(list(Path(".").iterdir())), shortened it to a truth-y list(...), then to a shorter any(Path(".")).iterdir().

Because I don’t need the length of (the elements in..) an iterator, I just need “does it have elements?”. I guess that’s why you can do any(Iterator) but not len(Iterator).

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus