Skip to main content
added 13 characters in body
Source Link
RomanPerekhrest
  • 93.1k
  • 4
  • 75
  • 112

Short solution using sum and enumerate functions:

tab = [80,12,14,5,70,9,26,30,8,12,16,15] sums = [sum(tab[i:i+4]) for i, v in enumerate(tab) if i+4 <= len(tab)] print(sums) 

The output:

[111, 101, 98, 110, 135, 73, 76, 66, 51] 

The last "4-items" consequent sequence to be summed up is 8,12,16,15(gives 51)

Short solution using sum and enumerate functions:

tab = [80,12,14,5,70,9,26,30,8,12,16,15] sums = [sum(tab[i:i+4]) for i, v in enumerate(tab) if i+4 <= len(tab)] print(sums) 

The output:

[111, 101, 98, 110, 135, 73, 76, 66, 51] 

The last "4-items" sequence to be summed up is 8,12,16,15(gives 51)

Short solution using sum and enumerate functions:

tab = [80,12,14,5,70,9,26,30,8,12,16,15] sums = [sum(tab[i:i+4]) for i, v in enumerate(tab) if i+4 <= len(tab)] print(sums) 

The output:

[111, 101, 98, 110, 135, 73, 76, 66, 51] 

The last "4-items" consequent sequence to be summed up is 8,12,16,15(gives 51)

Source Link
RomanPerekhrest
  • 93.1k
  • 4
  • 75
  • 112

Short solution using sum and enumerate functions:

tab = [80,12,14,5,70,9,26,30,8,12,16,15] sums = [sum(tab[i:i+4]) for i, v in enumerate(tab) if i+4 <= len(tab)] print(sums) 

The output:

[111, 101, 98, 110, 135, 73, 76, 66, 51] 

The last "4-items" sequence to be summed up is 8,12,16,15(gives 51)