https://github.com/hansalemaos/mixbalanced
Mixes the elements of multiple lists in a balanced manner based on their proportional lengths.
https://github.com/hansalemaos/mixbalanced
bisect sort
Last synced: 4 months ago
JSON representation
Mixes the elements of multiple lists in a balanced manner based on their proportional lengths.
- Host: GitHub
- URL: https://github.com/hansalemaos/mixbalanced
- Owner: hansalemaos
- License: mit
- Created: 2023-07-19T00:13:00.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-19T00:13:24.000Z (almost 3 years ago)
- Last Synced: 2025-12-15T04:46:15.843Z (6 months ago)
- Topics: bisect, sort
- Language: Python
- Homepage: https://pypi.org/project/mixbalanced/
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# Mixes the elements of multiple lists in a balanced manner based on their proportional lengths.
## pip install mixbalanced
#### Tested against Windows 10 / Python 3.10 / Anaconda
```python
This function takes multiple lists as input and returns a new list that contains the elements of the input lists.
The elements are combined in a balanced manner based on their proportional lengths. Longer lists contribute more
elements to the resulting list.
Parameters:
*args: Variable-length argument list, containing multiple lists/tuples.
Returns:
list: A new list containing the elements from the input lists/tuples mixed in a balanced manner.
Example:
from mixbalanced import mix_balanced
l1 = ["Antonio"] * 10
l2 = ["Paulo"] * 5
l3 = ["Anna"] * 15
l4 = ["Maria"] * 3
mix = mix_balanced(l1, l2, l3, l4)
print(mix)
Output: ['Anna', 'Antonio', 'Anna', 'Antonio', 'Paulo', 'Anna', 'Anna', 'Antonio', 'Anna', 'Maria',
'Anna', 'Antonio', 'Paulo', 'Anna', 'Antonio', 'Anna', 'Antonio', 'Paulo', 'Anna', 'Anna',
'Maria', 'Antonio', 'Anna', 'Antonio', 'Paulo', 'Anna', 'Anna', 'Antonio', 'Anna', 'Antonio',
'Paulo', 'Anna', 'Maria']
```