Skip to content

Commit

Permalink
Added common.remove_numeric_parentheses()
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Oct 28, 2024
1 parent ef65534 commit 3b6dc35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions t3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import os
import re
import string
from typing import Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -324,3 +325,17 @@ def get_o2_stoichiometry(smiles: Optional[str] = None,
if other:
raise ValueError(f'Cannot calculate O2 stoichiometry for {fuel.label} with {other} atoms which are not C/H/N/O.')
return 0.5 * (2 * c + 0.5 * h - o)


def remove_numeric_parentheses(input_string: str) -> str:
"""
Remove numeric parentheses from the end of a string.
Args:
input_string (str): The input string.
Returns:
str: The string without numeric parentheses.
"""
result = re.sub(r'\(\d+\)$', '', input_string)
return result

0 comments on commit 3b6dc35

Please sign in to comment.