-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update Enhanced Meshing workflow to cache data faster. (#2731)
* refactor: Update Enhanced Meshing workflow to cache data faster. * Caching. * Fix for renaming. * Renaming. * Fix for dynamic python names. * Move a dictionary operation to utils. * Refactoring. * Update a test. * Update logic. * test: test dict op (#2737) * added failing test * added test * Restructure. --------- Co-authored-by: Sean Pearson <[email protected]>
- Loading branch information
1 parent
82b8037
commit 1e1416a
Showing
4 changed files
with
108 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Performs some operations on Python dictionaries.""" | ||
|
||
from typing import Any | ||
|
||
|
||
def get_first_dict_key_for_value(input_dict: dict, value: Any): | ||
"""Get the first dictionary key that matches a value. Typical usage is where the | ||
value is known to be unique in the input dictionary. | ||
Parameters | ||
---------- | ||
input_dict : dict | ||
value : Any | ||
Returns | ||
------- | ||
Any | ||
Key associated with the first match. | ||
Raises | ||
------ | ||
ValueError | ||
If the value is absent from the dictionary. | ||
""" | ||
|
||
try: | ||
return next((key for key, val in input_dict.items() if val == value)) | ||
except StopIteration: | ||
raise ValueError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters