Login and get coding
You know the index at the end of a book where you look up which pages people and terms occur? Useful right?
In this Bite you will build your own, but instead of page numbers we will use line numbers.
We will be using the story of Little Red Riding Hood (the tests also run your code against The Needle Tree).
make_character_index(scroll down) that takes a multiline text (story) string and a list of characters.
Parse the text and match the characters (case insensitively) keeping track of the line numbers where they appeared.
One twist: some characters have synonyms, in that case you have to match them all and return the first one, e.g. when one of
('Grandmother', 'Grandma', 'Granny')matches, you return the first = Grandmother.
The return data is a
dictwhere the keys are the characters and the values are
lists of line numbers of (unique) appearances in sorted order.
See also the tests for the expected data.
We hope this is a fun exercise that keeps your Python fresh. Now go crack this Bite and remember: keep calm and code in Python!
Will you be Pythonista #223 to crack this Bite?
Resolution time: ~68 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.64 on a 1-10 difficulty scale.
» Up for a challenge? 💪