python中怎样删除二维数组同一行相同的数?
both previous grids with the modification that if a letter would appear more than once horizontally, then the second and subsequent occurrences are removed python 二维数组
[解决办法]
这个按照意思写就行了,如果已经有了,直接跳过,否则加入
>>> a=[['a','b','c','a'],
['e','b','d','f'],
['h','g','h','h']]
>>> a
[['a', 'b', 'c', 'a'], ['e', 'b', 'd', 'f'], ['h', 'g', 'h', 'h']]
>>> b = []
>>> c = []
>>> for m in a:
c = []
for n in m:
if n not in c:
c.append(n)
b.append(c)
>>> b
[['a', 'b', 'c'], ['e', 'b', 'd', 'f'], ['h', 'g']]
a=[['a','b','c','a'],
['e','b','d','f'],
['h','g','h','h']]
b = [list(set(x)) for x in a]
print(b)