KOTA ITO

Generation

generate functionFri, 16 Dec 2022

文字列の中から、「調査対象期間:」と「〜」に囲まれた日付の文字列だけを取得する

def get_date(date_str): start_index = date_str.find('調査対象期間:') end_index = date_str.find('〜') date_str_without_symbol = date_str[start_index + 6:end_index] date_list = date_str_without_symbol.split('/') date_list_with_zero = [] for date in date_list: if len(date) == 1: date_list_with_zero.append('0' + date) else: date_list_with_zero.append(date) return '-'.join(date_list_with_zero)

Questions about programming?Chat with your personal AI assistant