[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)
Wolfgang Maier
wolfgang.maier at biologie.uni-freiburg.de
Tue Aug 12 00:12:50 CEST 2014
On 11.08.2014 23:35, Ethan Furman wrote:
>
>> class Nasty:
>> def __radd__(self, other):
>> return other + "foo"
>>
>> "".join(["some", "strings", "and", "one", Nasty()])
>> sum(["some", "strings", "and", "one", Nasty()], "")
>
Interesting. So a slight variation enables sum-based string
concatenation *right now*:
class ZeroAdditionProperty:
def __add__(self, other):
return other
nullstr = ZeroAdditionProperty()
sum(["some", "strings", "and", "one"], nullstr)
Wolfgang
More information about the Python-ideas
mailing list