# Buggy code
def load(self, name, id):
    """Loads and sets this technique's attributes from the technique
    database. The technique is looked up in the database by name or id.

    :param name: The name of the technique to look up in the monster
        database.
    :param id: The id of the technique to look up in the monster database.

    :type name: String
    :type id: Integer

    :rtype: None
    :returns: None

    **Examples:**

    >>>

    """

    if name:
        results = techniques.lookup(name, table="technique")
    elif id:
        results = techniques.database["technique"][id]

    self.name = results["name"]
    self.name_trans = trans(results["name_trans"])
    self.tech_id = results["id"]
    self.category = results["category"]
    self.icon = results["icon"]

    self._combat_counter = 0
    self._life_counter = 0

    self.type1 = results["types"][0]
    if len(results["types"]) > 1:
        self.type2 = results["types"][1]
    else:
        self.type2 = None

    self.power = results["power"]
    self.effect = results["effects"]

    # TODO: maybe break out into own function
    from operator import itemgetter

    self.target = map(
        itemgetter(0),
        filter(
            itemgetter(1),
            sorted(results["target"].items(), key=itemgetter(1), reverse=True),
        ),
    )

    # Load the animation sprites that will be used for this technique
    self.animation = results["animation"]
    self.images = []
    animation_dir = prepare.BASEDIR + "resources/animations/technique/"
    directory = sorted(os.listdir(animation_dir))
    for image in directory:
        if self.animation and image.startswith(self.animation):
            self.images.append("animations/technique/" + image)

    # Load the sound effect for this technique
    sfx_directory = "sounds/technique/"
    self.sfx = sfx_directory + results["sfx"]


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def load(self, slug, id):
    """Loads and sets this technique's attributes from the technique
    database. The technique is looked up in the database by name or id.

    :param slug: The slug of the technique to look up in the monster
        database.
    :param id: The id of the technique to look up in the monster database.

    :type slug: String
    :type id: Integer

    :rtype: None
    :returns: None

    **Examples:**

    >>>

    """

    if slug:
        results = techniques.lookup(slug, table="technique")
    elif id:
        results = techniques.database["technique"][id]
    else:
        # TODO: some kind of useful message here
        raise RuntimeError

    self.slug = results["slug"]
    self.name = trans(results["name_trans"])
    self.tech_id = results["id"]
    self.category = results["category"]
    self.icon = results["icon"]

    self._combat_counter = 0
    self._life_counter = 0

    self.type1 = results["types"][0]
    if len(results["types"]) > 1:
        self.type2 = results["types"][1]
    else:
        self.type2 = None

    self.power = results["power"]
    self.effect = results["effects"]

    # TODO: maybe break out into own function
    from operator import itemgetter

    self.target = map(
        itemgetter(0),
        filter(
            itemgetter(1),
            sorted(results["target"].items(), key=itemgetter(1), reverse=True),
        ),
    )

    # Load the animation sprites that will be used for this technique
    self.animation = results["animation"]
    self.images = []
    animation_dir = prepare.BASEDIR + "resources/animations/technique/"
    directory = sorted(os.listdir(animation_dir))
    for image in directory:
        if self.animation and image.startswith(self.animation):
            self.images.append("animations/technique/" + image)

    # Load the sound effect for this technique
    sfx_directory = "sounds/technique/"
    self.sfx = sfx_directory + results["sfx"]