[New-bugs-announce] [issue9080] Provide list prepend method (even though it's not efficient)

Andy Buckley report at bugs.python.org
Fri Jun 25 14:00:49 CEST 2010


New submission from Andy Buckley <andy at insectnation.org>:

I know that Python lists aren't designed for efficient prepending, but sometimes when working with small lists it's exactly what needs to be done (search path lists being a common example). For a programmer aware of the performance issue and having convinced themself that it's not a problem for their use-case, it's a niggle that there is no prepend()  function for lists by direct analogy to the commonly-used append(). 

Writing l = ["foo"] + l, or something mucky based on l.insert(0, ...) or reverse/append/reverse is annoyingly asymmetric and no more performant. So I suggest that l.append(x) be added to the list interface, with a prominent warning in the documentation that it's not an efficient operation on that type (possibly mention the complexity scaling with list length). I think the role of the interface is to make simple things simple, not to make it difficult to do simple-but-inefficient things that people will do anyway ;)

----------
components: Library (Lib)
messages: 108587
nosy: andybuckley
priority: normal
severity: normal
status: open
title: Provide list prepend method (even though it's not efficient)
type: feature request
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9080>
_______________________________________


More information about the New-bugs-announce mailing list