Group list by values

后端 未结 7 1572
说谎
说谎 2020-12-01 03:09

Let\'s say I have a list like this:

mylist = [["A",0], ["B",1], ["C",0], ["D",2], ["E",2]]

相关标签:
7条回答
  • 2020-12-01 04:07
    values = set(map(lambda x:x[1], mylist))
    newlist = [[y[0] for y in mylist if y[1]==x] for x in values]
    
    0 讨论(0)
提交回复
热议问题