2 ms·
Nice tips. One nitpick: the "inline if statement" is handy because it works as an expression, not just as a statement. A few more useful things: frozenset: im
by shoo 14y ago
Nice tips. One nitpick: the "inline if statement" is handy because it works as an expression, not just as a statement.
A few more useful things:
frozenset: immutable set values. these can be hashed, so you can use them as keys in dicts or put them in sets.
poor-man's transpose via zip:
>>> x = [('a', 'b'), ('c', 'd')]
>>> zip(*x)
[('a', 'c'), ('b', 'd')]
slices can be constructed with the "slice" function and passed around as values:
>>> f = lambda x, s : x[s]
>>> first3 = slice(3)
>>> last3 = slice(-3, None)
>>> rev = slice(None, None, -1)
>>> f('hello', first3)
'hel'
>>> f('hello', last3)
'llo'
>>> f('hello', rev)
'olleh'