Re: [Pymoney-general] Currency's distrib() method
Brought to you by:
facundobatista
From: Darek S. <ds...@ti...> - 2005-07-01 09:42:39
|
Facundo Batista wrote: > 1. Returning the different currencies, splitting almost equally:: > > >>> Currency(1).distrib(3) > [Currency("0.33"), Currency("0.33"), Currency("0.34")] > >>> Currency(1).distrib(7) > [Currency("0.14"), Currency("0.14"), Currency("0.14"), > Currency("0.14"), Currency("0.15"), Currency("0.15"), > Currency("0.14")] > 2. Returning the almost exact part, with the rest (a kind of divmod() > but not to integers):: > > >>> Currency(1).distrib(3) > (Currency("0.33"), Currency("0.01")) > >>> Currency(1).distrib(7) > (Currency("0.14"), Currency("0.02")) > 3. Returning the different currencies, splitting differently:: > > >>> Currency(1).distrib([1,2]) > [Currency("0.33"), Currency("0.67")] > >>> Currency(3).distrib([2,1,3,3]) > [Currency("0.66"), Currency("0.33"), Currency("1.01"), Currency("1.00")] > > What do you think? Is it possible to have a combination of 1) and 3), with 1) being a special case of 3)? That is, something along the lines of: def distrib(self,nparts=None,proportions=None): if nparts: return self._real_distrib([1] * nparts) return self._real_distrib(proportions) darek |