How to separate a Python list into two lists, according to some aspect of the elements

后端 未结 8 769
小鲜肉
小鲜肉 2021-01-06 05:23

I have a list like this:

[[8, \"Plot\", \"Sunday\"], [1, \"unPlot\", \"Monday\"], [12, \"Plot\", \"Monday\"], [10, \"Plot\", \"Tuesday\"], [4, \"unPlot\", \"         


        
8条回答
  •  自闭症患者
    2021-01-06 06:03

    You could simply go through the list, and check if the value is "Plot" like this:

    for i in List:
      if i[1]=="Plot":
        list1.append(i)
      else:
        list2.append(i)
    

提交回复
热议问题