Answers for "python sorted multiple keys"

1

python sort two key

s = sorted(s, key = lambda x: (x[1], x[2]))
Posted by: Guest on May-07-2020
0

python sorted dictionary multiple keys

mylist = sorted(mylist, key=itemgetter('name', 'age'))
mylist = sorted(mylist, key=lambda k: (k['name'].lower(), k['age']))
mylist = sorted(mylist, key=lambda k: (k['name'].lower(), -k['age']))
Posted by: Guest on December-09-2020
4

python lambda key sort

>>> student_tuples = [
...     ('john', 'A', 15),
...     ('jane', 'B', 12),
...     ('dave', 'B', 10),
... ]
>>> sorted(student_tuples, key=lambda student: student[2])   # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
Posted by: Guest on May-23-2020
0

python sort multiple keys

records.sort(
  key = lambda l: (l[0], l[2])
)
Posted by: Guest on April-04-2020
0

python sort based on multiple keys

>>> def multisort(xs, specs):
...     for key, reverse in reversed(specs):
...         xs.sort(key=attrgetter(key), reverse=reverse)
...     return xs
Posted by: Guest on August-24-2020

Code answers related to "python sorted multiple keys"

Python Answers by Framework

Browse Popular Code Answers by Language