Here's a way to do what you've asked, assuming you want 2 decimals of precision on values converted from minutes to hours, which would match the format of the sample output in your question:
import re
A = ['15.1 total hours', '121 total mins', '7.1 total hours', '101 total mins']
B = []
for a in A:
m = re.search('([0-9]*\.?[0-9]*).*(hours|mins)', a)
value, unit = m.groups()
if unit == 'mins':
hourValue = float(value) / 60
a = a.replace(value, f"{hourValue:.2f}")
a = a.replace('mins', 'hours')
B.append(a)
A[:] = B
print(A)
Output:
['15.1 total hours', '2.02 total hours', '7.1 total hours', '1.68 total hours']
What we do is to search for a number ([0-9]*\.?[0-9]*)
which we save as a regular expression group (thanks to the parentheses) followed by 0 or more characters .*
followed by a second group (hours|mins)
which is either hours
or mins
. We then check if it's mins
, in which case we (1) convert the value from str to a float and divide by 60 to convert units from minutes to hours and (2) replace the original value with the new one at 2 decimals precision using f"{hourValue:.2f}"
and replace mins
with hours
without changing anything else in the string.