0
*** Variables ***

${base_url} https://api.github.com/

Search users with the following request parameters
    create session  Get_Repositories     ${base_url}             
    ${response_users} =    get request     Get_Repositories       /users
    #log to console     ${response_users.content}
    ${json_users} =        evaluate    json.loads('''${response_users.content}''')    json 
    ${Sorted_Users} =     Sort List         ${json_users}
    log to console        ${Sorted_Users}

I am receiving the error; TypeError: '<' not supported between instances of 'dict' and 'dict'

Pekka
  • 2,175
  • 15
  • 20

1 Answers1

0

Python does not automatically know how to compare dictionaries. You need to write your own sort function. A good example is in here: How do I sort a list of dictionaries by a value of the dictionary?

If you want to sort by "login" key, in Robot Framework it is like this:

${Sorted_Users}=    Evaluate    sorted(${json_users}, key=lambda d: d['login'])
Pekka
  • 2,175
  • 15
  • 20
  • Thank you so much!, all login/users are arranged ascendingly except the first one, can you tell why is it so? – Muhammad Feb 01 '22 at 16:38
  • That is because upper case letters are earlier than lower case. A workaround is to do a case-insensitive sort with "sorted(${json_users}, key=lambda d: d['login'].lower())" – Pekka Feb 02 '22 at 07:14