Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. # n = int(input('Введите число для которого нужно посчитать факториал\n'))
  2.  
  3. # fact = 1
  4. # for i in range(1, n + 1):
  5. #     fact *=i
  6. # print(fact)
  7.  
  8. # while n !=0
  9. #     fact = 1
  10. #     for i in range(1, n + 1):
  11. #         fact *= i
  12. # print(fact)
  13. # n = int(input('Введите число для которого нужно посчитать факториал\n'))
  14.  
  15. # while n !=0:
  16. #     factorial = lambda x: factorial(x-1) * x if x > 1 else 1
  17. #     print(factorial(n))
  18. #     n = int(input('Введите число для которого нужно посчитать факториал\n'))
  19.  
  20. # import numpy as np
  21. #
  22. # matrix = [[1,0,0,1,0],
  23. #           [0,1,0,1,0],
  24. #           [1,0,0,1,0],
  25. #           [0,0,0,0,0]]
  26. # print(np.matrix(matrix))
  27. # print("\n")
  28. # matrix_t = list(zip(*matrix))
  29. # print(np.matrix(matrix_t))
  30.  
  31. from urllib.request import urlopen
  32.  
  33. # {key1: value1, key2: value2, ...}
  34.  
  35. u = urlopen('http://python.org')
  36. words = {}
  37.  
  38. for line in u:
  39.     line = line.decode('utf-8')
  40.     line = line.strip(' \n')
  41.     for word in line.split(' '):
  42.         try:
  43.             words[word] += 1
  44.         except KeyError:
  45.             words[word] = 1
  46.  
  47. pairs = words.items()
  48. A = sorted(pairs, key=lambda x: x[1], reverse=True)
  49.  
  50. for i in A[:10]:
  51.     print(i[0], i[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement