Guest User

Untitled

a guest
Nov 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. a=input()
  2. aa=[int(s) for s in input().split()]
  3. b=input()
  4. bb=[int(s) for s in input().split()]
  5. c=input()
  6. cc=[int(s) for s in input().split()]
  7. sum=0
  8. for i in aa:
  9. if i in bb and i in cc:
  10. sum+=1
  11. print(sum)
  12.  
  13. aa = [1, 3, 1, 5, 7, 9]
  14. bb = [1,2,3,4]
  15. cc = [1,3,10]
  16.  
  17. chk = set(bb) & set(cc)
  18. print(chk)
  19. #{1, 3}
  20.  
  21. res = sum(x in chk for x in aa)
  22. print(res)
  23. #3
  24.  
  25. In [3]: %paste
  26. from random import randint
  27.  
  28. N = 10**4
  29. aa = [randint(0,1000) for _ in range(N)]
  30. bb = [randint(0,10**7) for _ in range(N)]
  31. cc = [randint(0,10**9) for _ in range(N)]
  32. ## -- End pasted text --
  33.  
  34. In [4]: %paste
  35. %%timeit
  36. sm=0
  37. for i in aa:
  38. if i in bb and i in cc:
  39. sm+=1
  40. ## -- End pasted text --
  41. 3.74 s ± 46.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
  42.  
  43. In [5]: %paste
  44. %%timeit
  45. chk = set(bb) & set(cc)
  46. res = sum(x in chk for x in aa)
  47. ## -- End pasted text --
  48. 5.16 ms ± 33.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
  49.  
  50. In [6]: 3.74 * 1000 / 5.16
  51. Out[6]: 724.8062015503875
Add Comment
Please, Sign In to add comment