根據條件拆分列表?

| | | | | | | | |

從美學和性能的角度來看,根據條件將項目列表拆分為多個列表的最佳方式是什麼?相當於:

good = [x for x in mylist if x in goodvals] bad = [x for x in mylist if x not in goodvals] 

有更優雅的方法嗎?

更新:這裡是實際用例,以更好地解釋我正在嘗試做的事情:

# files 看起來像:[ ("file1.jpg", 33L, ".jpg "), ("file2.avi", 999L, ".avi"), ... ] IMAGE_TYPES = (".jpg",".jpeg",".gif",".bmp",".png") images = [f for f in files if f[2].lower() in IMAGE_TYPES] anims = [f for f for f in files if f[2].lower() not in IMAGE_TYPES]