Make me beautiful (code needs help)
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Jul 23 11:05:49 EDT 2002
>
> 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.
>
why isn't data['new'][0] == 0? How can there be a difference between [0] and
[-1]?
def successive(the_list, place):
if place == 0: return 0
return the_list[place] - the_list[place - 1]
for i in range(1, len(data['A'])):
data['new'].append(successive(data['A'], i))
More information about the Python-list
mailing list