{ "cells": [ { "cell_type": "code", "execution_count": 14, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import numpy as np\n", "from typing import Iterable\n", "\n", "def gen_tranche_salary(\n", " nb_slices: int = 5, \n", " salary_start: int = 40,\n", " salary_end: int = 50,\n", ") -> Iterable[str]:\n", " coef_norm = 1.0 / float(nb_slices - 1)\n", " range_salaires = np.linspace(start=salary_start, stop=salary_end, num=nb_slices)\n", "\n", " def format_str_for_tranche_percent_range_salary(id_range_salary):\n", " i, (range_salary_min, range_salary_max) = id_range_salary\n", " # TODO: reformat with new style of string formatting `f{...}`\n", " return \"Tranche n°{} : {:>3.0%} - {:>4.0%} -> {:.2f}K - {:.2f}K\".format(\n", " i + 1, \n", " i * coef_norm,\n", " (i + 1) * coef_norm, \n", " range_salary_min,\n", " range_salary_max\n", " )\n", "\n", " for s in map(format_str_for_tranche_percent_range_salary,\n", " enumerate(zip(range_salaires[:-1:], range_salaires[1::]))):\n", " yield s" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tranche n°1 : 0% - 25% -> 45.00K - 46.25K\n", "Tranche n°2 : 25% - 50% -> 46.25K - 47.50K\n", "Tranche n°3 : 50% - 75% -> 47.50K - 48.75K\n", "Tranche n°4 : 75% - 100% -> 48.75K - 50.00K\n" ] } ], "source": [ "print(\"\\n\".join(gen_tranche_salary(nb_slices=5, salary_start=45, salary_end=50)))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }