Guest User

Untitled

a guest
Mar 24th, 2017
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. word1 = "fold"
  2. word2 = "arm"
  3. word3 = "breast"
  4.  
  5. bookscontent = [read_in(book) for book in books]
  6. books_tug = [find_in(book, word1) for book in bookscontent]
  7. books_tugs = [find_vicinity(bc, bt, "", 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
  8. books_tugs_tent = [find_vicinity(bc, bt, word2, 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
  9. books_tugs_tent2 = [find_vicinity(bc, bt, word3, 30) for book, bc, bt in zip(books, bookscontent, books_tug)]
  10.  
  11.  
  12.  
  13. res = defaultdict(list)
  14. for booknr, book in enumerate(bookscontent):
  15.     for i in books_tugs_tent[booknr]:
  16.         for j in books_tugs_tent2[booknr]:
  17.             if i[1] == j[1]:
  18.                 res[books[booknr]].append(' '.join(bookscontent[booknr][i[1]-30:i[1]+31]))
  19.  
  20.  
  21. print("Total:'"+word1+"'+'"+word2+"'+'"+word3+"'", len([item for sublist in [j for i,j in res.iteritems()] for item in sublist]))
  22. print("Total words", sum([len(book) for book in bookscontent]))
  23. 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]))
  24.  
  25. print("\n")
  26.  
  27. for j in books:
  28.     print("###########")
  29.     print(j,":", len(res[j]))
  30.     print("###########")
  31.     for i in res[j]:
  32.         print(i, end = "\n\n")
  33.  
  34.  
  35. for book, bc, bt in zip(books, bookscontent, res):
  36.     print(book, "|", len(res[bt]))
  37. 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