Is there a way to sort based on the attributes of the elements in the list?

Asked 2 years ago, Updated 2 years ago, 102 views

>>> ut
[<Tag: 128>, <Tag: 2008>, <Tag: <>, <Tag: actionscript>, <Tag: addresses>, <Tag: aes>, <Tag: ajax> ...]
>>> ut[1].count
1L

When we have the same list, ut, I'd like to sort the list down based on the attribute count of the element of ut.

What function should I use?

sorting python count

2022-09-22 16:51

1 Answers

ut.sort(key=lambda x: x.count, reverse=True)

newlist = sorted(ut, key=lambda x: x.count, reverse=True)

For more information on sorting using keys, see here


2022-09-22 16:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.