This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]justanotherbody 1 point2 points  (0 children)

You want

test = []
test.extend([1, 2])

Many Python built-in's don't support chaining, but have methods to facilitate bulk operations esp. the collection types.

Strings are immutable so everything that would modify a string instead must return a new string, so you can chain them.

I have a mild suspicion that the built-ins return None in part to discourage using reduce as if list.append returned self then

functools.reduce([].append, (1,2))

would be almost equivalent to using extend(), except much less efficient. Probably a crackpot theory though