首先定义一个compare函数:

def compare(sf1, sf2):
    if (sf1.value > sf2.value):
        return -1;
    elif (sf1.value == sf2.value):
        return 0;
    else:
        return 1; 

然后调用该函数就可以对List中的元素排序:

listA.sort(compare)

要求ListA中的元素有value这个属性才行,当然也可以把value换成ListA中的元素的其他共有属性也可以。感觉和Java差不多。

相关文章:

  • 2022-01-02
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
猜你喜欢
  • 2021-08-23
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
相关资源
相似解决方案