Need help with list of fractions

Matthew Wilson mwilson at sarcastic-horse.com
Fri Oct 10 11:15:44 EDT 2003


Hi-


I have a list of floats.  The list will always be 2^x+1 values, sorted,
between 0 and 1.

The smallest list would be [0, 0.5, 1].

I need a function that can get a list of any length, and return a new
list.  For example:

>>> foo([0, 1/2.0, 1])
[0, 1/3.0, 2/3.0, 1]

>>> foo([0, 1/4.0, 1/2.0, 3/4.0, 1])
[0, 1/5.0, 2/5.0, 3/5.0, 4/5.0, 1]

The output list will have 1 more element than the input list.

I can't (be bothered to) figure out how foo should work internally.  Maybe
somebody can help?  This stuff is not my strong suit.














More information about the Python-list mailing list