Python Sort a List containing sets -
any idea how sort list contains elements of type set ? code i'm using:
sorted_by_second = sorted(result_list, key=lambda set: set[1])
example of how result_list looks like:
[['past due', '32.86691794423967'], ['code', '23.24240338748313'], ['why:customer','27.65754595407057']]
i sort list descending order according 2nd element in each tupple of list elements. sorted list result should like
[['past due', '32.86691794423967'], ['why:customer','27.65754595407057'], ['code', '23.24240338748313']]
i suggest use float
map second element string number. allow sorted
sort numbers. if don't use float
, sorted
sort second element strings.
sorted(result_list, key=lambda x: float(x[1]), reverse=true)
result:
[['past due', '32.86691794423967'], ['why:customer', '27.65754595407057'], ['code', '23.24240338748313']]
hint: don't use set
name since it built-in function.
Comments
Post a Comment