I have the following dicti_1
:
{'2017-09-01': ['PRUEBAPRUEBA', 'PRUEBA123123'],
'2017-10-03': ['PRUEBAPRUEBA', 'PRUEBA123123'],
'2017-11-08': ['PRUEBAPRUEBA', 'PRUEBA123123'],
'2017-12-03': ['PRUEBA123123']}
I am looking forward to check the values that appear in the latest key (as it is a date):
In order to check the latest value that corresponds to the latest key what I did was :
EDIT: From @COLDSPEED input I sorted the dictionary , I used @Devin Jeanpierre 's answer in the following link in order to sort the dictionary using the operator module: How do I sort a dictionary by value?
sorted_dict = sorted(dicti_1.items(), key=operator.itemgetter(0))
latest_key=list(sorted_dict.keys())[-1]
return sorted_dict[latest_key]
After this I am looking forward to create a dictionary with the keys of the latest date and the values that appears:
return {latest_key:sorted_dict[latest_key]}
output:
{'2017-12-03': ['PRUEBA123123']}
However in my particular case, there is one latest value the 2017-12-03
which corresponds to PRUEBA123123
and a different value PRUEBAPRUEBA
with its latest date 2017-11-08
.
Therefore my desired output would be something like this:
new_dicti=
{'2017-12-03': ['PRUEBA123123'], '2017-11-08': ['PRUEBAPRUEBA']}
The problem I am facing is how to design new_dict with the latest date for every distinct value
Your help is highly appreciated.