Here I am try to sort the list of strings based on the one string, Here my test cases,
First Case:
par_str = "abcd"
list_str = ['bb','ba','ab']
sorted(list_str, key=par_str)
Output: ['ab','ba','bb']
Second Case:
par_str = "bacd"
list_str = ['bb','ba','ab']
sorted(list_str, key=par_str)
Output: ['bb','ba','ab']
From the First case list order changed based on par_str string. And Second test case the list order no change because it has same priority. So How to write above logic. I have tried but I am getting an error TypeError: 'str' object is not callable
keyargument insortedmust be a callable, as in not a string.par_str?sorted(list_str, key=par_str),key=par_stris wrong