On 08.07.20 17:19, Jonathan Fine wrote:
Hi All
This is related to discussion
https://mail.python.org/archives/list/[email protected]/thread/KWAOQFSV3YJYQV2Y5JXGXFCXHJ3WFLRS/#ZT3OBOPNIMXQ2MU7N5RFBL5AJSYRZJ6Q
In Python, lists don't have a join method. Instead, it's strings that
have the join method. Hence we have:
>>> ', '.join('abcde')
'a, b, c, d, e'
The intermediate method we can save and store and use again.
>>> joiner = ', '.join
>>> joiner('fghijk')
'f, g, h, i, j, k'
We can do something similar when clamping, clipping or trimming a
value. For example, suppose we want limits on the room temperature,
that the thermostat cannot override.
>>> aircon_clipper = Clamper(50, 80)
>>> thermostat_temp = 40
>>> target_temp = aircon_temp_clipper(thermostat_temp)
>>> target_temp
50
You could also use `functools.partial` for that purpose:
aircon_clipper = partial(clamp, min=50, max=80)
So a (builtin) function serves this purpose as well.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/4KJ6QOIVCJ6ZMOAVEWUTMP2NCMFR7D5D/
Code of Conduct: http://python.org/psf/codeofconduct/