Skip to content

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.

Notifications You must be signed in to change notification settings

jomasego/process_and_calculate_python_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Data Processing Utilities for Test🛠️

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.

Files 📁

concatenate.py 🔗

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 📚

Examples: 💡

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}

cost_prorating.py 💰

A utility for prorating costs based on weights. This function distributes a total cost among different items based on their relative weights.

Features: ⭐

  • Handles zero weights
  • Validates inputs (non-negative costs and weights)
  • Distributes costs proportionally
  • Handles edge cases

Examples: 💡

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]

Requirements 📋

  • Python 3.7 or higher 🐍
  • No external dependencies required ✨

Installation 🚀

  1. Clone this repository
  2. No additional installation steps required as only standard Python libraries are used

Usage 🔨

You can either:

  1. Import the functions into your own Python code:
from concatenate import concatenate_same_type
from cost_prorating import cost_prorating
  1. Run the files directly for interactive mode:
python concatenate.py
python cost_prorating.py

Error Handling ⚠️

Both utilities include comprehensive error handling:

  • Type validation ✅
  • Input validation ✅
  • Edge case handling ✅

License 📄

No license at all. The code is yours to use, sell or acknowledge 😊


Made with ❤️ by jomasego, in Madrid, Spain

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages