Re: [Pymoney-general] Re: Hello and some questions.
Brought to you by:
facundobatista
From: Darek S. <ds...@us...> - 2005-05-23 08:46:34
|
Batista, Facundo wrote: Hi, > #- What about that case? > #- > #- >>> Currency(1).distrib(7) > #- > #- Should it be > #- > #- (Currency('0.16'), Currency('0.14'), Currency('0.14'), > #- Currency('0.14'), > #- Currency('0.14'), Currency('0.14'), Currency('0.14')) > #- > #- or > #- > #- (Currency('0.15'), Currency('0.15'), Currency('0.14'), > #- Currency('0.14'), > #- Currency('0.14'), Currency('0.14'), Currency('0.14')) ? > > The latter. And it must be defined if the bigger ones will be at the > beggining, at the end, or in random places in the structure (I'm not > choosing one of the options, but we must define which we'll choose and then > use it). Hm, did you really mean *random* here? Couldn't it be simply implementation-dependent? Perhaps something along the lines of: distrib(amount, n[, sorted=False[, descending=False]]) Returns amount distributed into n parts as uniformly as possible. Optional argument sorted indicates that the result should be sorted (in ascending order by default). If sorted is given and not False, and optional fourth argument descending is not False, the result will be returned in descending order. If sorted is False or omitted, the order of returned parts is implementation-dependent. Two caveats. 1. "as uniformly as possible" is vague, and while I can create some testcases and I *know* that >>> Currency(1).distrib(7) should return (Currency('0.15'), Currency('0.15'), Currency('0.14'), Currency('0.14'), Currency('0.14'), Currency('0.14'), Currency('0.14')) I'm not sure how to express it in a manner that would leave no doubts. 2. sorted is a builtin in 2.4 darek |