The hardest problem in computer science...

Ethan Furman ethan at stoneleaf.us
Sat Jan 7 14:05:28 EST 2017


On 01/06/2017 11:34 PM, Steve D'Aprano wrote:
> On Sat, 7 Jan 2017 12:03 am, Steve D'Aprano wrote:
>>> The second hardest problem in computer science is cache invalidation.
>>>> The *hardest* problem is naming things.
>> After puzzling over this for three days, it suddenly hit me:
>> Theme = namedtuple("Theme", "vline tee corner")
>> DEFAULT = Theme("│ ", "├─ ", "└─ ")
> BOLD = Theme("┃ ", "┣━ ", "┗━ ")
> ASCII = Theme("| ", "|- ", "+- ")
>> def draw_tree(tree, theme=DEFAULT):
> ...

Ya know, that looks an /awful/ lot like a collection! Maybe even an Enum? ;)
-- 8< -------------------------------------------------------
from aenum import Enum # note the 'a' before the 'enum' :)
class Theme(Enum, init='v vr llc'):
 DEFAULT = "│ ", "├─ ", "└─ "
 BOLD = "┃ ", "┣━ ", "┗━ "
 ASCII = "| ", "|- ", "+- "
def draw_tree(tree, theme=Theme.DEFAULT):
 print(theme.v)
 print(theme.vr)
 print(theme.v)
 print(theme.llc)
draw_tree(None)
-- 8< -------------------------------------------------------
--
~Ethan~


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /