Make me beautiful (code needs help)
Duncan Booth
duncan at NOSPAMrcp.co.uk
Wed Jul 24 07:22:19 EDT 2002
[posted and mailed]
Mark <Hobbes2176 at yahoo.com> wrote in
news:HVd%8.6582$I4.1825 at nwrddc03.gnilink.net:
> data["A"] = [1,2,4,10,50]
>
> and I want to get:
>
> data["new"] = [?, 1, 2, 6, 40]
>
> That is, I want to get the successive differences into their proper
> place. I don't care what is in the question mark spot. I'll figure
> that out later.
How about this?
>>> from __future__ import generators
>>> def adjacent(it):
it = iter(it)
value = it.next()
for value2 in it:
yield value, value2
value = value2
>>> a = [1, 2, 4, 10, 50]
>>> print [ q-p for p,q in adjacent(a)]
[1, 2, 6, 40]
>>>
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list