Joining lists
Mark Pilgrim
f8dy at my-deja.com
Wed Jan 31 12:47:20 EST 2001
In article <mailman.980940576.15930.python-list at python.org>,
jurgen.defurne at philips.com wrote:
> Hello, list members,
>
> Is there a simple way of joining two list to form only one list,
like :=
>
> [1, 5, 6, 4] <join operation> [4, 6, 7] -> [1, 5, 6, 4, 4, 6, 7]
The extend method of a list will do this for you.
>>> li = [1, 5, 6, 4]
>>> li.extend([4, 6, 7])
[1, 5, 6, 4, 4, 6, 7]
You can also use the + operator.
>>> li = [1, 5, 6, 4]
>>> li + [4, 6, 7]
[1, 5, 6, 4, 4, 6, 7]
More examples of adding, removing, and finding items in lists:
http://diveintopython.org/odbchelper_list.html
Short summary of all list methods:
http://www.python.org/doc/current/lib/typesseq-mutable.html
-M
--
You're smart; why haven't you learned Python yet?
http://diveintopython.org/
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list