Skip to content

Commit

Permalink
style: inline loop to multiline loop
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPic committed Sep 6, 2024
1 parent 517c532 commit 9c2a92c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions idf_analysis/little_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,22 @@ def timedelta_components_plus(td, min_freq='min'):


def timedelta_components_readable(l, short=False, sep=', '):
s = sep.join(
['{}{}{}'.format(v, '' if short else ' ', c[0] if short else (c if v > 1 else c[:-1])) for v, c in l if v > 0])
result = []
for value, label_component in l:
if value > 0:
if short:
unit_sep = ''
unit = label_component[0]
else:
unit_sep = ' '
unit = label_component
if value > 1:
unit = label_component[:-1]

result.append(f'{value}{unit_sep}{unit}')

s = sep.join(result)

if not short:
# replace last "," with "and"
s = ' and '.join(s.rsplit(sep, 1))
Expand Down

0 comments on commit 9c2a92c

Please sign in to comment.