1
$\begingroup$

I've been trying the expression node with x.sort(key = lambda o: o.name), but it gives no result. How can I sort objects by name in this situation?

$\endgroup$

1 Answer 1

1
$\begingroup$

expression sorted(x, key = lambda o: o.name) works well.

$\endgroup$
1
  • $\begingroup$ The explanation is because the sortmethod modifies the list in place and doesn't return a value, while sorted returns a new, sorted, list and doesn't change the input list. $\endgroup$
    – Gorgious
    Jun 19, 2020 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .