Contact: aviboots(AT)netvision.net.il
41,395 questions
53,941 answers
573 users
lst = [2, 3, 4, 5, 6, 7] products = [a * b for a, b in zip(lst, lst[1:])] print(products) # 2 * 3 = 6 # 3 * 4 = 12 # 4 * 5 = 20 # 5 * 6 = 30 # 6 * 7 = 42 ''' run: [6, 12, 20, 30, 42] '''
def products_pair_consecutive_items(lst): result = [] for i in range(len(lst) - 1): product = lst[i] * lst[i + 1] result.append(product) return result lst = [2, 3, 4, 5, 6, 7] print(products_pair_consecutive_items(lst)) # 2 * 3 = 6 # 3 * 4 = 12 # 4 * 5 = 20 # 5 * 6 = 30 # 6 * 7 = 42 ''' run: [6, 12, 20, 30, 42] '''