Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
metaclass=Singleton solution in Clear category for Capital City by martin.pilka
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class Capital(metaclass=Singleton):
def __init__(self, city_name):
self.city_name = city_name
def name(self):
return self.city_name
Feb. 5, 2019