get the sum of differences between integers in a list

Daiyue Weng daiyueweng at gmail.com
Tue Sep 20 07:52:12 EDT 2016


Hi, I have a list numbers say,

[1,2,3,4,6,8,9,10,11]

First, I want to calculate the sum of the differences between the numbers
in the list.
Second, if a sequence of numbers having a difference of 1, put them in a
list, i.e. there are two such lists,

[1,2,3]

[8,9,10,11]

and also put the rest numbers in another list, i.e. there is only one such
list in the example,

[6].

Third, get the lists with the max/min sizes from above, i.e. in this
example, the max list is,

[8,9,10,11]

min list is

[1,2,3].

What's the best way to implement this?

cheers



More information about the Python-list mailing list