Created
December 12, 2018 13:59
-
-
Save SuvroBaner/476b66f6ccfc11e2ec8abd5af336a6f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
books = ['The Lord of the Rings', 'The Hobbit', 'Harry Potter and the Chamber of Secrets', | |
'Black Beauty', 'Kane and Abel', 'To Kill a Mocking Bird', 'Gitanjali', | |
'Spring and Autumn Annals', 'Rumi Poems'] # defining a list of books | |
book_catalog = {} # defining a dictionary | |
for book in books: | |
book_index = book[0] # extract the first letter (for catalog) | |
if book_index not in book_catalog: | |
book_catalog[book_index] = [book] | |
else: | |
book_catalog[book_index].append(book) # appending the book if the index already exists in the catalog | |
book_catalog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment