2 回答
TA贡献1809条经验 获得超8个赞
像这样怎么样:
array([['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', 'E', 'A', 'G', 'L', 'E', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', 'P', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', 'P', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', 'L', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', 'E', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0']], dtype='<U1')
def grid_mapper(grid, t=False):
word = ''
coords = []
for idx, vals in enumerate(grid):
if sum(map(str.isalpha, vals)) < 2:
continue
else:
for i, v in enumerate(vals):
if v.isalpha():
word += v
if not t:
coords.append((idx, i))
else:
coords.append((i, idx))
else:
continue
return word, coords
res = dict()
for g in [(a,), (a.T, True)]:
w, c = grid_mapper(*g)
res[w] = c
print(res)
{'EAGLE': [(7, 5), (7, 6), (7, 7), (7, 8), (7, 9)],
'APPLE': [(7, 6), (8, 6), (9, 6), (10, 6), (11, 6)]}
添加回答
举报