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
$\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 '20 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.