Re:Playing with Strings and Colors in Python
by mmcnickle on Friday December 28, 2012 @01:13PM
(#4978725)
I'm not sure if you were looking for any criticism. I found the way that the way the ATTRIBUTES, HIGHLIGHTS and COLORS dicts are defined to be unnecessarily difficult to read:
It may feel like you are being more DRY by not typing the numerical values out. But this is data and it's perfectly fine to explicitly define them. The result is straightforward, more compact and easier to read as a result:
[ Parent
| on HN ]
Re:Playing with Strings and Colors in Python
by viraptor on Friday December 28, 2012 @01:44PM
(#4978891)
Or even this if you don't want explicit numbers, but don't want that many zip/list/dict/range/etc.:
attrs = ['bold', 'dark', '', 'underline', 'blink', '', 'reverse', 'concealed']
ATTRIBUTES = dict((k,v) for v,k in enumerate(attrs, 1) if k)
# or
ATTRIBUTES = dict(zip(itertools.count(1), attrs))