Python has the "timedelta" class in the datetime module - it can't parse the quantities above, but you can, with some minimal parsing, create timedelta objects which are directly comparable (and can be added and subtracted directly to normal date or datetime objects);
In [1]: from datetime import timedelta
In [5]: x = timedelta(weeks=40)
In [6]: x
Out[6]: datetime.timedelta(280)
timedelta can take weeks, years, days and seconds as keyweord parameters, but not months since their lenght is not well defined. Also, the most usual way of creating a timedelta is by subtracting two date (or datetime) objects.
This small function takes advantage of the time units you are using being almost the same that are accepted as a timedelta constructor to save some lines in parsing your time differences in English and creating a timedelta object from them, using regular expressions:
import re
from datetime import timedelta
def get_timedelta(line):
timespaces = {"days": 0}
for timeunit in "year month week day hour minute second".split():
content = re.findall(r"([0-9]*?)\s*?" + timeunit, line)
if content:
timespaces[timeunit + "s"] = int(content[0])
timespaces["days"] += 30 * timespaces.pop("months", 0) + 365 * timespaces.pop("years", 0)
return timedelta(**timespaces)
And using the examples you provide, one has:
In [26]: lines = """7 months
11 months
1 hour, 24 minutes
10 months, 3 weeks
1 year
1 year, 1 month
8 months, 2 weeks
2 months
2 months, 4 weeks
8 months, 1 week
9 months, 3 weeks""".split("\n")
In [27]: for line in lines:
print(get_timedelta(line))
....:
210 days, 0:00:00
330 days, 0:00:00
1:24:00
321 days, 0:00:00
365 days, 0:00:00
395 days, 0:00:00
254 days, 0:00:00
60 days, 0:00:00
88 days, 0:00:00
247 days, 0:00:00
291 days, 0:00:00