I have the following dict:
All the values are either strings or None or empty or Boolean (True/False)
{
'id': None,
'last_login': None,
'is_superuser': False,
'is_staff': False,
'date_joined': '2019-10-06',
'password': 'pbkdf2_sha256$150000$zXmhAd1NIgI4$1wMGVVDGTSCXZmdFtIoIB/aB3/4nfMn6DnYIuXeRyr8=',
'last_login_passwd': None,
'last_login_otp': None,
'last_password_change': None,
'first_name': '',
'last_name': '',
'email': '',
'is_active': False,
'otp_pass_change': '',
'first_otp_passlogin_create': '',
'first_otp_otplogin_create': '',
'about': '',
'location': '',
'birth_date': None,
'first_otp_login_created_date': None,
'first_pass_login_created_date': None,
'modified_date': None}
Now i want to see this dict sorted based on values and then based on keys.
{
'is_active' : FALSE,
'is_staff' : FALSE,
'is_superuser' : FALSE,
'about' : '',
'email' : '',
'first_name' : '',
'first_otp_otplogin_create' : '',
'first_otp_passlogin_create' : '',
'last_name' : '',
'location' : '',
'otp_pass_change' : '',
'password' : 'pbkdf2_sha256$150000$zXmhAd1NIgI4$1wMGVVDGTSCXZmdFtIoIB/aB3/4nfMn6DnYIuXeRyr8=',
'date_joined' : '2019-10-06',
'birth_date' : None,
'first_otp_login_created_date' : None,
'first_pass_login_created_date' : None,
'id' : None,
'last_login_otp' : None,
'last_login_passwd' : None,
'last_login' : None,
'last_password_change' : None,
'modified_date' : None,
}
How can i do that.
I TRIED:
test = {
'id': None,
'last_login': None,
'is_superuser': False,
'is_staff': False,
'date_joined': '2019-10-06',
'password': 'pbkdf2_sha256$150000$zXmhAd1NIgI4$1wMGVVDGTSCXZmdFtIoIB/aB3/4nfMn6DnYIuXeRyr8=',
'last_login_passwd': None,
'last_login_otp': None,
'last_password_change': None,
'first_name': '',
'last_name': '',
'email': '',
'is_active': False,
'otp_pass_change': '',
'first_otp_passlogin_create': '',
'first_otp_otplogin_create': '',
'about': '',
'location': '',
'birth_date': None,
'first_otp_login_created_date': None,
'first_pass_login_created_date': None,
'modified_date': None}
sorted(test.items(), key=lambda kv: kv[1], reverse=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-41-453676f7d0ed> in <module>
22 'first_pass_login_created_date': None,
23 'modified_date': None}
---> 24 sorted(hare.items(), key=lambda kv: kv[1], reverse=True)
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'