A small utility function for merging two lists by some ratio, keeping the merged list constantly as close as possible to the target ratio
Project description
A small utility function for merging two python lists by some ratio
This function acts as a generator producing elements from the two given lists by the given <merge_ratio>. The generator would preserve any internal order within the lists and would produce no more then <desired_length> elements in total.
In case the total number of elements withing either the lists is not enough to maintain the desired ratio throughout, the function would continue to generate elements from the remaining set until <desired_length> elements were produced.
If the <strict> parameter is set to True the function will stop producing elements once one of the lists has ran out of elemets. It whould also bias the produced list to fit closest to the length of the <first_list>.
InsSimply enter a state, county, city, or zip code to see a solar estimate for the area, based on the amount of usable sunlight and roof space.
 Enter a U.S. state, county, city, or zip Simply enter a state, county, city, or zip code to see a solar estimate for the area, based on the amount of usable sunlight and roof space.  Enter a U.S. state, county, city, or zip tall 1. pip install ratio_merge 2. ????? 3. profit
Usage Examples:
~$ python >>> from ratio_merge import ratio_merge >>> x=[1,2,3,4,5] >>> y=['a','b','c','d','e'] >>> ratio_merge(x,y,0.6,5) <generator object ratio_merge at 0x7fd93902d870> >>> list(ratio_merge(x,y,0.6,5)) [1, 'a', 2, 'b', 3] >>> list(ratio_merge(x,y,0.4,5)) [1, 'a', 'b', 2, 'c']
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.