Code: Select all
input_list = list('aaddccdc')
input_list.sort(key=lambda i: (-input_list.count(i), ord(i)))
print(input_list)
< /code>
Wir erhalten das Ergebnis in unerwarteter Reihenfolge < /p>
['a', 'a', 'c', 'c', 'c', 'd', 'd', 'd']
Code: Select all
input_list = list('aaddccdc')
snapshot = input_list.copy()
input_list.sort(key=lambda i: (-snapshot.count(i), ord(i)))
print(input_list)
< /code>
Wir erhalten die unterschiedliche, erwartete Reihenfolge < /p>
['c', 'c', 'c', 'd', 'd', 'd', 'a', 'a']
Mobile version