2 ms·
Language specifics mean that this might not always be the case. i.e. >>> s = "%03d" >>> f = lambda x: s % x # Identical behavior for a regular function
by falcolas 16y ago
Language specifics mean that this might not always be the case. i.e.
>>> s = "%03d"
>>> f = lambda x: s % x # Identical behavior for a regular function closure
>>> map(f, range(10))
['000', '001', '002', '003', '004', '005', '006', '007', '008', '009']
>>> s = "%04d"
>>> map(f, range(10))
['0000', '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009']
I would try and think of it as more of a function parameter that you pre-fill, and never have to provide again for that instance of the function.