Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created April 12, 2022 15:00
Show Gist options
  • Save Steboss89/98018de40e4e6e5b0bc031e0ad0935ea to your computer and use it in GitHub Desktop.
Save Steboss89/98018de40e4e6e5b0bc031e0ad0935ea to your computer and use it in GitHub Desktop.
First approach from int to string to list
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