Advertisement
agel122

Untitled

Nov 17th, 2021
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. my_data = {'2021-01-01': 'data1',
  2.            '2021-02-22': 'data2',
  3.            '2021-03-11': 'data3',
  4.            '2021-03-12': 'data4',
  5.            '2021-12-30': 'data5'}
  6.  
  7.  
  8. def data_search(my_data, start_data, end_data):
  9.     my_data_selected = {}
  10.     start_value = start_data[5:7] + start_data[-2:]
  11.     end_value = end_data[5:7] + end_data[-2:]
  12.     my_data_selected = {key: my_data[key] for key in my_data.keys()
  13.                         if start_value <= key[5:7] + key[-2:] <= end_value}
  14.     """for key in my_data.keys():
  15.        if start_value <= key[5:7]+ key[-2:] <= end_value:
  16.            my_data_selected[key] = my_data[key]"""
  17.     return my_data_selected
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     selection = data_search(my_data, '2021-01-01', '2021-09-01')
  22.     print(selection)
  23.     assert data_search(my_data, '2021-01-01', '2021-01-01') == {'2021-01-01': 'data1'}
  24.     assert data_search(my_data, '2021-02-02', '2021-02-30') == {'2021-02-22': 'data2'}
  25.     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