This repository contains utility functions for data processing and cost calculations. ⚙️They were part of a test, but now they are public for anyone wanting to use them.
A utility that concatenates lists of same-type elements with different behaviors based on the data type:
- Integers/Floats: Sums all numbers 🔢
- Strings: Joins strings with '|' separator 📝
- Booleans: Converts to '1' (True) and '0' (False) and concatenates ✅
- Lists: Flattens nested lists into a single list 📋
- Dictionaries: Merges dictionaries 📚
concatenate_same_type([1, 2, 3]) # Output: 6
concatenate_same_type(['hello', 'world', 'python']) # Output: hello|world|python
concatenate_same_type([True, False, True, True]) # Output: 1011
concatenate_same_type([[1, 2], [3, 4], [5, 6]]) # Output: [1, 2, 3, 4, 5, 6]
concatenate_same_type([{'a': 1}, {'b': 2}, {'c': 3}]) # Output: {'a': 1, 'b': 2, 'c': 3}
A utility for prorating costs based on weights. This function distributes a total cost among different items based on their relative weights.
- Handles zero weights
- Validates inputs (non-negative costs and weights)
- Distributes costs proportionally
- Handles edge cases
cost_prorating(100, [10, 20, 70]) # Output: [10, 20, 70]
cost_prorating(100, [1, 1, 1]) # Output: [34, 33, 33]
cost_prorating(7, [1, 2, 3, 0]) # Output: [1, 2, 4, 0]
- Python 3.7 or higher 🐍
- No external dependencies required ✨
- Clone this repository
- No additional installation steps required as only standard Python libraries are used
You can either:
- Import the functions into your own Python code:
from concatenate import concatenate_same_type
from cost_prorating import cost_prorating
- Run the files directly for interactive mode:
python concatenate.py
python cost_prorating.py
Both utilities include comprehensive error handling:
- Type validation ✅
- Input validation ✅
- Edge case handling ✅
No license at all. The code is yours to use, sell or acknowledge 😊
Made with ❤️ by jomasego, in Madrid, Spain