5 ms·
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 dif
by mmcnickle 14y ago
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:
ATTRIBUTES = dict(
list(zip([
'bold',
'dark',
'',
'underline',
'blink',
'',
'reverse',
'concealed'
],
list(range(1, 9))
))
)
del ATTRIBUTES['']
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:
ATTRIBUTES = {
'bold': 1,
'dark': 2,
'underline': 4,
'blink': 5,
'reverse': 7,
'concealed': 8
}
- viraptor 14y agoOr 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))