From 7f6fff34e577fecfa85fcea19a420ca1e59f7687 Mon Sep 17 00:00:00 2001 From: DhruvDuseja Date: Fri, 20 Oct 2023 09:06:39 +0400 Subject: [PATCH] use dict comprehension; doc update; changelog update --- CHANGELOG.md | 6 ++++++ src/pyEQL/utils.py | 9 +++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 016310d7..7ee082e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- `format_solutes_dict()` method added into the utils module to help format solutes dictionaries with a unit. + ## [0.9.0] - 2023-10-17 ### Added diff --git a/src/pyEQL/utils.py b/src/pyEQL/utils.py index e162368a..13da2884 100644 --- a/src/pyEQL/utils.py +++ b/src/pyEQL/utils.py @@ -40,21 +40,18 @@ def format_solutes_dict(solute_dict: dict, units: str): Args: solute_dict: The dictionary to format. This must be of the form dict{str: Number} e.g. {"Na+": 0.5, "Cl-": 0.9} - units: The units to use for the solute. + units: The units to use for the solute. e.g. "mol/kg" Returns: A formatted solute dictionary. Raises: - TypeError if `solute_dict` is invalid. + TypeError if `solute_dict` is not a dictionary. """ if not isinstance(solute_dict, dict): raise TypeError("solute_dict must be a dictionary. Refer to the doc for proper formatting.") - for key, value in solute_dict.items(): - solute_dict[key] = f"{value!s} {units}" - - return solute_dict + return {key: f"{value!s} {units}" for key, value in solute_dict.items()} class FormulaDict(UserDict):