Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my_data = {'2021-01-01': 'data1',
- '2021-02-22': 'data2',
- '2021-03-11': 'data3',
- '2021-03-12': 'data4',
- '2021-12-30': 'data5'}
- def data_search(my_data, start_data, end_data):
- my_data_selected = {}
- start_value = start_data[5:7] + start_data[-2:]
- end_value = end_data[5:7] + end_data[-2:]
- my_data_selected = {key: my_data[key] for key in my_data.keys()
- if start_value <= key[5:7] + key[-2:] <= end_value}
- """for key in my_data.keys():
- if start_value <= key[5:7]+ key[-2:] <= end_value:
- my_data_selected[key] = my_data[key]"""
- return my_data_selected
- if __name__ == '__main__':
- selection = data_search(my_data, '2021-01-01', '2021-09-01')
- print(selection)
- assert data_search(my_data, '2021-01-01', '2021-01-01') == {'2021-01-01': 'data1'}
- assert data_search(my_data, '2021-02-02', '2021-02-30') == {'2021-02-22': 'data2'}
- assert data_search(my_data, '2021-03-12', '2021-12-30') == {'2021-03-12': 'data4', '2021-12-30': 'data5'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement