Best way to insert sorted in a list

Ethan Furman ethan at stoneleaf.us
Fri Jun 17 18:24:20 EDT 2011


Chris Torek wrote:
> Appending to the list is much faster, and if you are going to
> dump a set of new items in, you can do that with:
> 
>     # wrong way:
>     # for item in large_list:
>     #    a.append(item)
>     # right way, but fundamentally still the same cost (constant
>     # factor is much smaller due to built-in append())
>     a.append(large_list)
          ^- should be a.extend(large_list)

~Ethan~



More information about the Python-list mailing list