How to do a case-insensitive sort of pathlib.Path objects?

Viewed 344

I'd like to do a case-insensitive sort of pathlib.Path objects based on their filenames i.e. their str representation.

By default, calling sorted() on a list of Path objects will sort them, but is case-sensitive.

Things I've tried:

>>> sorted(p, key=str.lower)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'lower' for 'str' objects doesn't apply to a 'PosixPath' object
>>> sorted(p, key=lambda path: str(path).lower)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'builtin_function_or_method' and 'builtin_function_or_method'

It feels like there should be an easy way to do this that I'm missing.

0 Answers
Related