Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
UserDict 2nd solution in Clear category for Cipher Crossword by gyahun_dash
from collections import UserDict
from itertools import chain, permutations
class ConsistentDict(UserDict):
def __setitem__(self, key, item):
if key not in self: self.data[key] = item
elif self[key] != item: raise ValueError
def checkio(crossword, words):
line = list(chain(*chain(crossword[::2], list(zip(*crossword))[::2])))
for keywords in permutations(words):
try: cdict = ConsistentDict(zip(line, ''.join(keywords)))
except ValueError: continue
else: return [[cdict.get(n, ' ') for n in row] for row in crossword]
Sept. 27, 2014