Make me beautiful (code needs help)
Mark
Hobbes2176 at yahoo.com
Tue Jul 23 10:40:39 EDT 2002
Ok, I have the following data:
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.
Here's my current code:
for i in range(len(data["A"])):
try:
data["new"].append(data["A"][i] - data["A"][i-1])
except OutOfBounds:
data["new"].append("?")
Now, the other problem, is that in general, I want to fill data["new"] with
an arbitary function of the values in data["A"]. As a dumb example, I
might want to fill data["new"] with copies of the mean (average) of
data["A"]. So, in some cases, the new values are relative to the current
location (ie i and i-1) and in other they are absolute (ie all of them).
I can certainly hack through this, but I'm looking for something pretty. I
know python is up to it.
Regards,
Mark
More information about the Python-list
mailing list