extension to list extend

J

James Stroud

Found that this would be handy today:

alist = [1, 2, 3]
alist.extend(['a', 'b', 'c'], 1)
alist == [1, 'a', 'b', 'c', 2, 3] # True

James

--
James Stroud
UCLA-DOE Institute of Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
 
J

James Stroud

Peter said:
James said:
Found that this would be handy today:

alist = [1, 2, 3]
alist.extend(['a', 'b', 'c'], 1)
alist == [1, 'a', 'b', 'c', 2, 3] # True

A better name for that would be insert(), but that is already used for
single-item insertion. For the time being you can do
items = [1, 2, 3]
items[1:1] = "abc"
items
[1, 'a', 'b', 'c', 2, 3]

Thanks! It looks much nicer too.

James

--
James Stroud
UCLA-DOE Institute of Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Importing to 0
overloading *something 11
WTF? 4
Python Pseudo-Switch 3
pdb question - spew out "steps" until crash needed 2
dict subclass and pickle bug (?) 4
Python & SSL 9
Help text embedding in C code? 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top