# Exercise from https://www.pythonmorsels.com/

class EasyDict():
    def __init__(self, *arg, **kwargs):
        """The arguments, i.e. dict content is added to the dict and then any keyword argument is 
           also added, only the `normalize` argument is implemented at the moment."""
        if arg:
            self.__dict__.update(arg[0])
        if kwargs:
            self.__dict__.update(kwargs)
    
    def __getitem__(self, key):
        """Method to get the items themselves, can be changed with normalize parameter."""
        if 'normalize' in self.keys():
            return self.__dict__[key.replace('_', ' ')]
        else:
            return self.__dict__[key]

    def __setitem__(self, key, value):
        """Method to set a value of a key in the dict-style class."""
        self.__dict__[key] = value
    
    def keys(self):
        return self.__dict__.keys()

    def get(self, key, default=None):
        """Getter that allows also to get the value by direct reference."""
        if key in self.__dict__.keys():
            return self.__dict__[key]
        return default
        
    def __eq__(self, other):
        """Method used for == comparison."""
        if isinstance(other, EasyDict) and self.keys() == other.keys(): 
            return all([self[key] == other[key] for key in self.__dict__.keys()])
        return False


# Example usage

person = EasyDict({'name': "Trey Hunner", 'location': "San Diego"}, normalize=True)

person.keys()

person['nick name'] = 'Petr'

person.nick_name

