Light Mode
Dark Mode
I wonder how dict(zip(keys, values)) works

To solve Cipher Crossword, I've defined the following class inherited UserDict, and tried to find a mapping in all possible combinations of numbers and letters in checkio.

class ConsistentDict(collections.UserDict):
    def __setitem__(self, key, item):
        if not key in self.keys(): self.data[key] = item
        elif self[key] != item: raise ValueError #prohibit updates

def checkio(words):
    for letters in permutations(words):
        try: cdict = ConsistentDict(zip(numbers, letters))
        except ValueError: continue

I wanted to use dict, but ConsistentDict inherited dict didn't work in my code.

I'm just wondering that dict's behavior (when argument is zip) is defferent from UserDict's.

Created: March 10, 2014, 12:23 p.m.
Updated: May 19, 2014, 2:27 p.m.
0
44
User avatar
gyahun_dash