- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to sum the consecutive numbers with overlapping elements in lists, a list comprehension, list slicing, concatenation operator and ‘zip’ methods are used.

Below is a demonstration of the same −

my_list = [41, 27, 53, 12, 29, 32, 16] print("The list is :") print(my_list) my_result = [a + b for a, b in zip(my_list, my_list[1:] + [my_list[0]])] print("The result is :") print(my_result)

The list is : [41, 27, 53, 12, 29, 32, 16] The result is : [68, 80, 65, 41, 61, 48, 57]

A list of integers is defined and is displayed on the console.

A list comprehension is used to iterate over the elements.

The ‘zip’ method is used to obtain specific indices of the list and concatenate them using the ‘+’ operator.

This result is converted to a list and is assigned to a variable.

This variable is displayed as output on the console.

- Related Questions & Answers
- Sum of consecutive numbers in JavaScript
- Consecutive Numbers Sum in C++
- Program to count number of consecutive lists whose sum is n in C++
- Program to find largest sum of 3 non-overlapping sublists of same sum in Python
- Program to find numbers with same consecutive differences in Python
- Python Program for cube sum of first n natural numbers
- Python Program for Sum of squares of first n natural numbers
- Program to find maximum sum of two non-overlapping sublists in Python
- Print all possible sums of consecutive numbers with sum N in C++
- Program to find concatenation of consecutive binary numbers in Python
- Program to find maximum number of non-overlapping subarrays with sum equals target using Python
- Program to find two non-overlapping sub-arrays each with target sum using Python
- Program to find kpr sum for all queries for a given list of numbers in Python
- C++ Program for Sum of squares of first n natural numbers?
- C Program for cube sum of first n natural numbers?

Advertisements