7 ms·
This is a great, if somewhat basic list. My $0.02: Python is a tool for thinking clearly. That you can run your "thoughts" as written is a very nice bonus, of
by calroc 13y ago
This is a great, if somewhat basic list. My $0.02: Python is a tool for thinking clearly. That you can run your "thoughts" as written is a very nice bonus, of course.
There are some really interesting things that Python allows:
>>> d = {}
>>> d[23], d[14], d['hmm'] = 'abc'
>>> d
{'hmm': 'c', 14: 'b', 23: 'a'}
- calroc 13y agoI couldn't resist. Moar funky-cool Python: >>> from string import ascii_letters >>> ors = ['|'] * (len(ascii_letters) * 2 - 1) >>> ors[::2] = ascii_letters >>> ''.join(ors) 'a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z' (Obviously, in this example '|'.join(ascii_letters) would suffice, but if the objects weren't strings...)
- beambot 13y agoNot gonna lie... your snippet made me say "WTF?" Why not just do: from string import ascii_letters '|'.join( ascii_letters ) (I also like list slicing... but only when necessary.)
- calroc 13y agoYeah, I realized after posting it. (See edit.) The original code was using non-string objects. I basically come up with this to get the same behavior as str.join(). ;-)
- jerf 13y ago'|'.join(str(x) for x in y) # or '|'.join(map(str, y))
- calroc 13y agoThe original use for that code was to build a list of parsing objects to create a single parsing object that was the OR'ing of the basic ones. Aw, heck, code speaks louder than words: https://github.com/PhoenixBureau/PigeonComputer/blob/master/pigeon/cola/bubbles.py#L200 https://github.com/PhoenixBureau/PigeonComputer/blob/master/...
- jerf 13y agointersperseM or $ map chartok whitespace Oh... wait... sorry... wrong language.