Provided, your example data
['2017-01' '2017-01' '2017-01' ... '2021-03' '2021-10' '2021-12']
is an array (and you simply forgot the commas) the following would extract the months for a give year
dates = ['2017-01', '2017-01', '2017-01', '2021-03', '2021-10', '2021-12']
monthsOfYear = [i[5:] for i in dates if i.startswith('2021-') ]
print(monthsOfYear)
and output of the print will be:
['03', '10', '12']
I hope it helps.