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

Asked 1 years ago, Updated 1 years ago, 89 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.