我有一个包含数字的列表列表如下:
scc = [[6], [17, 7], [11, 10, 20, 1], [8, 18, 22, 13, 3], [4, 14, 23, 28, 9, 27, 19, 25, 24, 5, 15, 31, 30, 12, 26, 21, 2]]
和使用过的数字列表如下:
used = [6,7,20,4]
我想从scc列表中删除那些使用过的数字,如果任何列表归结为一个元素,我想从中删除该元素,我想从scc中删除整个列表。
scc = [[number for number in group if number not in used] for group in scc]
scc = [[], [17], [11, 10, 20, 1], [8, 18, 22, 13, 3], [14, 23, 28, 9, 27, 19, 25, 24, 5, 15, 31, 30, 12, 26, 21, 2]]
但我想删除scc中的列表,如果它的长度是== 0,就像第一个列表一样,那么scc就会被输出:
scc = [[17], [11, 10, 20, 1], [8, 18, 22, 13, 3], [14, 23, 28, 9, 27, 19, 25, 24, 5, 15, 31, 30, 12, 26, 21, 2]]
有优雅的方法吗?