Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. new_list = [1, 2, 3, 4, 5, 6]
  2. new_list_1 = [2, 3, 4, 5, 6, 7]
  3. dist = []
  4.  
  5. for index in range(len(new_list)):
  6. x1 = new_list[index]
  7. x2 = new_list[index+1]
  8. y1 = new_list_1[index]
  9. y2 = new_list_1[index+1]
  10. distance_1 = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
  11. dist.append(distance_1)
  12. index += 1
  13.  
  14. print(dist)
  15.  
  16. new_list = [1, 2, 3, 4, 5, 6]
  17. new_list_1 = [2, 3, 4, 5, 6, 7]
  18.  
  19.  
  20. dst = lambda xy1, xy2: ((xy1[0] - xy2[0]) ** 2 +
  21. (xy1[1] - xy2[1]) ** 2
  22. )** 0.5
  23.  
  24. def pairs(seq1, seq2):
  25. itr = iter(zip(seq1, seq2))
  26. prev = next(itr)
  27. while True:
  28. cur = next(itr)
  29. yield (prev, cur)
  30. prev = cur
  31.  
  32. result = [dst(pair[0], pair[1]) for pair in pairs(new_list, new_list_1)]
  33.  
  34. print(result)
  35.  
  36. xs = 1, 2, 3, 4, 5, 6
  37. for x1, x2 in zip(xs, xs[1:]):
  38. print(f"x1={x1}, x2={x2}")
  39.  
  40. x1=1, x2=2
  41. x1=2, x2=3
  42. x1=3, x2=4
  43. x1=4, x2=5
  44. x1=5, x2=6
  45.  
  46. xs = [1, 2, 3, 4, 5, 6]
  47. ys = [2, 3, 4, 5, 6, 7]
  48. points = list(zip(xs, ys))
  49. distances = [((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
  50. for (x1, y1), (x2, y2) in zip(points, points[1:])]
  51.  
  52. 1.4142135623730951 1.4142135623730951 1.4142135623730951
  53. 1.4142135623730951 1.4142135623730951
  54.  
  55. a = [1,2,3,4,5,6]
  56. b = [2,3,4,5,6,7]
  57. for i in range(0:len(a)//2):
  58. lets_do_some_math(a[2*i],b[2*i],a[2*i+1],b[2*i+1])
  59.  
  60. new_list = [1, 2, 3, 4, 5, 6]
  61. new_list_1 = [2, 3, 4, 5, 6, 7]
  62. dist = []
  63.  
  64. for index in range(len(new_list)):
  65. try:
  66. x1 = new_list[index]
  67. x2 = new_list[index + 1]
  68.  
  69. y1 = new_list_1[index]
  70. y2 = new_list_1[index + 1]
  71.  
  72. distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
  73. dist.append(distance)
  74.  
  75. except IndexError:
  76. pass
  77.  
  78. print(dist)
  79.  
  80. [1.4142135623730951, 1.4142135623730951, 1.4142135623730951, 1.4142135623730951, 1.4142135623730951]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement