Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list1 = [2, 3, 5, 1, 10, -2, 5]
- # ---- oryginal ---
- list2 = []
- iterations = len(list1) - 1
- position = 1
- for i in range(0, iterations):
- denominator = (list1[position])
- list2.append(list1[i] / denominator)
- position = position + 1
- print(list2)
- # ---- with all modifications but still with range(len()) ---
- list2 = []
- for i in range(len(list1)-1):
- list2.append(list1[i] / list1[i+1])
- print(list2)
- # ---- without range(len()) ---
- list2 = []
- for a, b in zip(list1, list1[1:]):
- list2.append(a/b)
- print(list2)
- # --- as list comprehension ---
- list2 = [a/b for a, b in zip(list1, list1[1:])]
- print(list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement