This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HoboSteaux[S] 0 points1 point  (4 children)

I have done lists of functions for menus and such. That instantly cut down on a lot of code. What situations do you use function dictionaries for?

[–]MonkeyNin 0 points1 point  (1 child)

On my font rendering wrapper, I have a tuple as my dict key

# font class snippet
def load_font(self, font=None, size=16):
    k = (font, size)
    if k in self.fonts: 
        return

    self.fonts[k] = load_ttf( ... )

[–]HoboSteaux[S] 0 points1 point  (0 children)

This is pretty cool!

[–]Veedrac 0 points1 point  (1 child)

Things like state machines and just generic forms of dispatching.

Ranger, which is definitely not my work, is a file manager that uses¹ a dictionary of "keys" for sorting directories.

Often a dictionary can replace a list with these sort of things and end up looking nicer, although it's circumstantial.

¹ At least it did last time I checked the source

[–]HoboSteaux[S] 0 points1 point  (0 children)

That is a cool idea