On Sun, May 24, 2020 at 02:27:00PM +0300, Ram Rachum wrote: > Today I wrote a script and did this: > > sorted(paths, key=lambda path: len(str(path)), reverse=True) > > But it would have been nicer if I could do this: > > sorted(paths, key=len, reverse=True)
It would have been even nicer if we could compose functions: sorted(paths, key=lenāstr, reverse=True) *semi-wink* > So I implemented `PurePath.__len__` as `str(len(path))`. > > Serhiy and Remi objected, because it might not be obvious that the length > of the path would be the length of string. It isn't obvious to me that the length of a path is the length of the string representation of that path. I thought that the length of the path would be the number of path components: /tmp/file # length 2 I wouldn't have predicted that was the length of the string representation of the path. -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RHOPEZHLIPN5OVHNQGGT55VF5OBG4RJX/ Code of Conduct: http://python.org/psf/codeofconduct/