Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- word1 = "fold"
- word2 = "arm"
- word3 = "breast"
- bookscontent = [read_in(book) for book in books]
- books_tug = [find_in(book, word1) for book in bookscontent]
- books_tugs = [find_vicinity(bc, bt, "", 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
- books_tugs_tent = [find_vicinity(bc, bt, word2, 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
- books_tugs_tent2 = [find_vicinity(bc, bt, word3, 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
- res = defaultdict(list)
- for booknr, book in enumerate(bookscontent):
- for i in books_tugs_tent[booknr]:
- for j in books_tugs_tent2[booknr]:
- if i[1] == j[1]:
- res[books[booknr]].append(' '.join(bookscontent[booknr][i[1]-30:i[1]+31]))
- print("Total:'"+word1+"'+'"+word2+"'+'"+word3+"'", len([item for sublist in [j for i,j in res.iteritems()] for item in sublist]))
- print("Total words", sum([len(book) for book in bookscontent]))
- print("'"+word1+"'+'"+word2+"'+'"+word3+"' per word", float(len([item for sublist in [j for i,j in res.iteritems()] for item in sublist]))/sum([len(book) for book in bookscontent]))
- print("\n")
- for j in books:
- print("###########")
- print(j,":", len(res[j]))
- print("###########")
- for i in res[j]:
- print(i, end = "\n\n")
- for book, bc, bt in zip(books, bookscontent, res):
- print(book, "|", len(res[bt]))
- print("total |",len([item for sublist in [j for i,j in res.iteritems()] for item in sublist]))
Add Comment
Please, Sign In to add comment