Java vs Python – sorting of objects

Най-късия код, който намерих на Java за сортиране на списък
Collections.sort(employees, new Comparator() {
public int compare(Employee e1, Employee e2) {
String id1 = ((Employee) e1).getId();
String id2 = ((Employee) e2).getId();
// ascending order
return id1.compareTo(id2);
// descending order
//return id2.compareTo(id1);


Същото на Python
somelist.sort(key = lambda x: x.resultType)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.