Created
April 12, 2022 15:00
-
-
Save Steboss89/98018de40e4e6e5b0bc031e0ad0935ea to your computer and use it in GitHub Desktop.
First approach from int to string to list
This file contains hidden or 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
| numbers = [] | |
| for i in range(0,100001): | |
| # convert a number to string | |
| numbers.append(num2words(i)) | |
| # clean the book and obtain the data list | |
| # for each book collect the number occurrences | |
| numb_dict = {} | |
| for i, book in enumerate(data, 0): | |
| # split the string from spaces | |
| splitter = book.split() | |
| book_name = book_list[i] | |
| for number in numbers: | |
| # count the occurences for a specific number | |
| occurrences = splitter.count(number) | |
| # add this to a counter in the final dictionary | |
| if book_name in numb_dict: | |
| numb_dict[book_name][number] = occurrences | |
| else: | |
| numb_dict[book_name] = {number:occurrences} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment