python列表的一个问题
有两个列表A,B
A = [[[3, 5], [0, 2], [2, 10]], [[6, 9], [7, 2], [9, 7]], [[3, 3], [5, 3], [10, 2]]];
B = [[0, 2], [2, 10], [3, 3]];
B中的每个元素都在A中,出现过记做1,否则为0
怎么得到[[0, 1, 1], [0, 0, 0], [1, 0, 0]]? python list
[解决办法]
你又发这儿来了,[0,1,1]是怎么来的啊?
[解决办法]
好了,还是去那边看到了描述,你写反了,是检测A中元素在B中的次数
>>> A = [[[3, 5], [0, 2], [2, 10]], [[6, 9], [7, 2], [9, 7]], [[3, 3], [5, 3], [10, 2]]]
>>> B = [[0, 2], [2, 10], [3, 3]]
>>> C = [[B.count(x) for x in y] for y in A]
>>> C
[[0, 1, 1], [0, 0, 0], [1, 0, 0]]