Consider the following example str of dates:
'20180101,20180102,20180103,20180104,20180105,20180106,20180107,20180108,20180109,20180110,20180111,20180112,20180113,20180114,20180115,20180116,20180117,20180118,20180119,20180120,20180121,20180122,20180123,20180124,20180125,20180126,20180127,20180128,20180129,20180130,20180131,20180201,20180202,20180203,20180204,20180205,20180206,20180207,20180208'.
Using .replace('2018','2018-'), or re.sub('2018', '2018-', foo_string) from the module re, a date changes to 2018-0101. However, I'd like to insert a hyphen for a range of dates. I have tried the following re.sub('{}'.format(range(2018,2019)), '2018-', foo_string) to no avail. The string is returned without any changes. For reference the years I'd like to range over for the hyphen are 1981 to 2018.
Additionally, I'm unsure of a way to insert a hyphen between the month and dates in a clean way. Help along these directions would be greatly appreciated.
20180101to be2018-01-01?