How to sort the list in the correct order?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
14 views
You need to in the beginning was the values in the specified order, not the specified values are sorted as usual.

lst = ['asd', 'aaa', 'str1', 'str2', 'str3'] order = ['str1', 'str3'] result = ['str1', 'str3', 'aaa', 'asd', 'str2']
by | 14 views

1 Answer

0 like 0 dislike
sublist = [item for item in lst if item not in order]
sublist.sort()
result = order + sublist
by

Related questions

0 like 0 dislike
1 answer
asked Aug 7, 2019 by Leniorko
0 like 0 dislike
1 answer
asked May 22, 2019 by hatepls
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked May 23, 2019 by AlmazKayum
0 like 0 dislike
1 answer
asked May 3, 2019 by Program_Danil
110,608 questions
257,187 answers
0 comments
40,796 users