I have a list of Objects: [variable , variable , variable , ...] which each have an array called domain. As example: variable.domain = ["aa" , "bbb" , "c" , "dddd"]. I need this variable list sorted by the size of the domain arrays. How can i sort this list using .sort() or .sorted() ?
Asked
Active
Viewed 120 times
1 Answers
2
Use a key function
sorted(l, key=lambda x: len(x.domain))
or
l.sort(key=lambda x: len(x.domain))

Patrick Haugh
- 59,226
- 13
- 88
- 96