How to Sort a List of Dictionaries in Python

How to Sort a List of Dictionaries in Python

Pretty Printed

5 лет назад

21,806 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Vishal Trivedi
Vishal Trivedi - 03.09.2022 04:36

Thanks!!!

Ответить
Smsng2 Xprss
Smsng2 Xprss - 02.05.2022 15:43

Difference between itemgetter and attrgetter ?

Ответить
Terry Lengel
Terry Lengel - 15.03.2022 23:42

After extensive looking for sort method of larger lists of dictionaries, this is the very best!

Ответить
Machinima Aquinix
Machinima Aquinix - 19.10.2021 21:14

Big thumbs up. Was super-helpful and did the operation exactly as I needed it for my use case.

Ответить
Maycon Douglas
Maycon Douglas - 03.09.2021 20:05

Very nice video! Helped me a lot.

Ответить
Sparsh Goyal
Sparsh Goyal - 30.08.2021 21:20

How to sort the list in the alphabetic order when the age for more than one entry is same???

Ответить
Fransisco Vinueza
Fransisco Vinueza - 05.12.2020 20:37

Do you have and idea a third way to sort a list of dicts by a group of keys. I figure out using sort, lambda dictionary and itemgetter. Its an exercise of my studies that i cant figure out!

Ответить
Saym A
Saym A - 19.04.2020 10:46

How can u use keys index number instead of name? Do u just put 0,1 etc inside the
parentheses after itemgettr?

Ответить
Sean Musse
Sean Musse - 18.04.2020 14:45

I've been trying to solve this problem for a whole day... Thank you so much! Straight to the point and well produced, subscribed and I hope to see more videos like these :)

Ответить
송현서
송현서 - 10.04.2020 19:56

Thank you very much. This video is nice. :)

Ответить
Moosky Navti
Moosky Navti - 09.04.2020 13:50

Helpful video. Please how can you add another record (dictionary) to the one above
For instance what will be the function to add
{'name' : 'Pretty', 'join_date' : '2020--03-03', 'age' : 23 }
How can one add this dictionary to the users above

Ответить
Stargate
Stargate - 05.03.2020 18:57

Thank you for your sharing =)

Ответить
MCDaddy
MCDaddy - 18.01.2020 23:51

Helped me with a problem i could not figure out. Thank you!

Ответить
BasicMaths
BasicMaths - 31.10.2019 14:30

i hv a column of lists. And those hv nested dictionaries inside the list. . How to extract all keys in separate columns?

Ответить
Sriram R
Sriram R - 18.07.2019 08:27

len(subscribers) += 1

Ответить
Turdle
Turdle - 30.06.2019 23:48

Siq ty

Ответить
Bhuvnesh Saini
Bhuvnesh Saini - 09.02.2019 15:06

How to update list of dictionary on specific index

Ответить
Deya Nemo
Deya Nemo - 31.10.2018 18:17

thanks allot 🙂

Ответить
陈俊杰
陈俊杰 - 23.09.2018 03:35

Could you show us how to deploy a flask app with docker on windows in LAN? Thanks

Ответить
שחר יצחק
שחר יצחק - 19.09.2018 21:44

Still waiting for flask socket io heroku toturial :)

Ответить
Kobas
Kobas - 08.09.2018 02:36

Great video. I needed that utility recently and could have not make it. I've also noticed a huge improvement in terms of content flow and explanation. Good job!

Ответить
John Snow
John Snow - 06.09.2018 03:54

Something to keep in mind: when you work with large lists of dicts(~1Mil) itemgetter slows things down abit. Therefore I use lambda magic...
sorted(users, key=lambda k: k['name'])

I use this almost every day ... It's very efficient.

Ответить
John Dupuy
John Dupuy - 05.09.2018 23:22

If you find yourself doing such sorts quite a bit, I've written a library called "PLOD" that is available on PyPI. it's strength, in part, is that it handles edge cases well, such as missing keys and the like. You can so something like:

newlist = PLOD(oldlist).sort('name', none_greater=True, reverse=True).returnList(limit=10)

That creates a new list sorted by 'name' in reverse but where missing names are put on top. Programmers interested in adding to the open source library are welcome :).

Ответить
Dmitry Vlasov
Dmitry Vlasov - 05.09.2018 18:06

Also we can use many fields with itemgetter('join_date','age',....). Here is a question: In SQL notation we use different order like this: "order by join_date asc,age desc". What about Python's list sorting?

Ответить
Abhishek Kalia
Abhishek Kalia - 05.09.2018 14:50

Are you also the creator of the nodejs master class?

Ответить