2 ms·
Good idea, sometimes. On the opposite end, I will sometimes go out of my way to name something when there isn't an immediately apparent need. Also naming can
by a3n 11y ago
Good idea, sometimes.
On the opposite end, I will sometimes go out of my way to name something when there isn't an immediately apparent need.
Also naming can often shorten up a long line.
Trivial example:
In [15]: SortByLen = lambda x: len(x)
In [16]: SortByLast = lambda x: x[-1]
In [17]: listOfInterest = ['123', '234', '432''12', '12345', '123']
In [18]: sorted(listOfInterest, key=SortByLen)
Out[18]: ['123', '234', '123', '43212', '12345']
In [19]: sorted(listOfInterest, key=SortByLast)
Out[19]: ['43212', '123', '123', '234', '12345']