from hashids import Hashids


class Shortener(object):

    def __init__(self, secret, min_length, short_url_domain):
        self.secret = secret
        self.min_length = min_length
        self.short_url_domain = short_url_domain
        self._hasher = None

    def get_short_id(self, number):
        if self._hasher is None:
            self._hasher = Hashids(self.secret, self.min_length)
        return self._hasher.encode(number)

    def get_short_url(self, short_id):
        return f'http://{self.short_url_domain}/{short_id}'

from hashids import Hashids


class Shortener(object):

    def __init__(self, secret, min_length, short_url_domain):
        self.secret = secret
        self.min_length = min_length
        self.short_url_domain = short_url_domain
        self._hasher = Hashids(self.secret, self.min_length)

    def get_short_id(self, number):
        return self._hasher.encode(number)

    def get_short_url(self, short_id):
        return f'http://{self.short_url_domain}/{short_id}'

Move hasher creation to constructor
Move hasher creation to constructor

  from hashids import Hashids
  
  
  class Shortener(object):
  
      def __init__(self, secret, min_length, short_url_domain):
          self.secret = secret
          self.min_length = min_length
          self.short_url_domain = short_url_domain
-         self._hasher = None
+         self._hasher = Hashids(self.secret, self.min_length)
  
      def get_short_id(self, number):
-         if self._hasher is None:
-             self._hasher = Hashids(self.secret, self.min_length)
          return self._hasher.encode(number)
  
      def get_short_url(self, short_id):
          return f'http://{self.short_url_domain}/{short_id}'
  
Move hasher creation to constructor
## Code Before:
from hashids import Hashids


class Shortener(object):

    def __init__(self, secret, min_length, short_url_domain):
        self.secret = secret
        self.min_length = min_length
        self.short_url_domain = short_url_domain
        self._hasher = None

    def get_short_id(self, number):
        if self._hasher is None:
            self._hasher = Hashids(self.secret, self.min_length)
        return self._hasher.encode(number)

    def get_short_url(self, short_id):
        return f'http://{self.short_url_domain}/{short_id}'

## Instruction:
Move hasher creation to constructor
## Code After:
from hashids import Hashids


class Shortener(object):

    def __init__(self, secret, min_length, short_url_domain):
        self.secret = secret
        self.min_length = min_length
        self.short_url_domain = short_url_domain
        self._hasher = Hashids(self.secret, self.min_length)

    def get_short_id(self, number):
        return self._hasher.encode(number)

    def get_short_url(self, short_id):
        return f'http://{self.short_url_domain}/{short_id}'
