import
re
def
swap_name_date(books
=
[]):
ordered_book_list
=
[]
regex_pattern
=
re.
compile
(r
'([\w ]+) \((\d{4})\)'
)
for
book
in
books:
res
=
regex_pattern.sub(
'\g<2> - \g<1>'
,book)
ordered_book_list.append(res)
ordered_book_list.sort()
for
book
in
ordered_book_list:
print
(book)
if
__name__
=
=
"__main__"
:
unordered_books_list
=
[
"City of Glass (2009)"
,
"The Great Gatsby (1925)"
,
"Pride and Prejudice (1813)"
,
"The Hunger Games (2008)"
,
"To Kill a Mockingbird (1960)"
,
"The Notebook (1996)"
,
"Jane Eyre (1847)"
,
"The Catcher in the Rye (1951)"
,
"The Lord of the Rings (1954)"
,
"All the light We Cannot See (2014)"
,
"Immortals of Meluha (2010)"
]
swap_name_date(unordered_books_list)