Re: get the sum of differences between integers in a list

2016-09-23 Thread Peter Otten
Daiyue Weng wrote: > i, I am new to the advanced python techniques, and by studying your code, > I understand that when calling grouped function with values[1, 2, 3, 6, 8, > 9, 10, 11, 13, 17, 19], > > tee(values, 3) generated 3 iterators shared values > > left contains [1, 2, 3, 6, 8, 9, 10, 11

Re: get the sum of differences between integers in a list

2016-09-21 Thread Steve D'Aprano
On Thu, 22 Sep 2016 01:51 am, marco.naw...@colosso.nl wrote: > And here is a straightforward one without any helpers: Please don't do people's homework for them. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.p

Re: get the sum of differences between integers in a list

2016-09-21 Thread marco . nawijn
On Wednesday, September 21, 2016 at 4:14:10 PM UTC+2, Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having

Re: get the sum of differences between integers in a list

2016-09-21 Thread Peter Otten
Peter Otten wrote: > This is not as efficient as it should be -- the gaps are calculated twice, > the check for the first and the last position is repeated on every > iteration lots of packing and unpacking... -- To address some of my own criticism: def lonely(triple): left, value, right =

Re: get the sum of differences between integers in a list

2016-09-21 Thread Peter Otten
Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having a difference of 1 between them, > put them in a list,

Re: get the sum of differences between integers in a list

2016-09-21 Thread Daiyue Weng
Hi, first of all, let me rephase the problem. For an arbitrary list of integers (the integers in the list are not necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], if a set of consecutive integers having a difference of 1 between them, put them in a list, i.e. there are two such lists in

Re: get the sum of differences between integers in a list

2016-09-20 Thread John Pote
On 20/09/2016 12:52, Daiyue Weng wrote: 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. At least for this first part a little pencil, paper and algebra yields a simple formula of constant and minimal c

Re: get the sum of differences between integers in a list

2016-09-20 Thread mm0fmf
On 20/09/2016 12:52, Daiyue Weng wrote: What's the best way to implement this? With a python script. Show your work and people will help you. -- https://mail.python.org/mailman/listinfo/python-list

Re: get the sum of differences between integers in a list

2016-09-20 Thread Peter Otten
Daiyue Weng wrote: > 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

Re: get the sum of differences between integers in a list

2016-09-20 Thread Steve D'Aprano
On Tue, 20 Sep 2016 09:52 pm, Daiyue Weng wrote: > 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. Sounds like homework. What have you tried? Hint: use the sum() function to sum a list of num

get the sum of differences between integers in a list

2016-09-20 Thread Daiyue Weng
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 nu