Files
courses/py3interm/EXAMPLES/sort_holmes.py
T
2025-05-20 11:57:43 -04:00

27 lines
667 B
Python

#!/usr/bin/env python
"""Sort titles, ignoring leading articles"""
books = [
"A Study in Scarlet",
"The Sign of the Four",
"The Hound of the Baskervilles",
"The Valley of Fear",
"The Adventures of Sherlock Holmes",
"The Memoirs of Sherlock Holmes",
"The Return of Sherlock Holmes",
"His Last Bow",
"The Case-Book of Sherlock Holmes",
]
def strip_articles(title): # <.>
title = title.lower()
for article in 'a ', 'an ', 'the ':
if title.startswith(article):
title = title[len(article):] # <.>
break
return title
for book in sorted(books, key=strip_articles): # <.>
print(book)