筛选字符串符合条件的字符串

img


怎么样才能判断距离该节日天数小于10天,并且提取出所在字符串


import re
str_tuple = ('距离春节还有-245', '距离国庆节还有3', '距离清明节还有-5')

for str_ in str_tuple:
    num = int(str_.split('有')[-1])
    if 0 < num < 10:
        holiday = re.search('距离(.*)还有', str_).group(1)
        print(holiday)

不太好弄,因为农历节日在公历上不固定。需要引入个万年历的库去解决。