操纵列表以解决难题

时间:2015-12-07 11:38:17

标签: python list puzzle

我有一个清单:

mylist=[[1,2],[2,3,5],[1,3],[5,8,6],[5,9],[4],[7],[6,8,9],[4,9,8,6]] 

它是数独的一行,每个列表代表每个案例的可能性。

我的目标是创建一个可以从5删除mylist[1]的函数;因为123只能位于list[0][1][2]

我正在寻找提示

我想出了

def epure(dimension, length):
    repeated=[i for sublist in [x for x in dimension if len(x)==length] for i in sublist]
    repeated=list(set([x for x in repeated if repeated.count(x)==length]))
    for n in dimension:
        for item in repeated:
            if item in n and len(n)!=length:
                n.remove(item)
    return dimension

但它失败了,我现在正在努力。

0 个答案:

没有答案
相关问题