Faqts : Business : Programming : Shopping For You : Python : Common Problems : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 17 people (6%) answered Yes
Recently 1 of 10 people (10%) answered Yes

Entry

how to form a list containing the union of the elements of two lists?

Oct 29th, 2007 04:20
Alexander Skwar, Robby Stephenson, lili1688 c, http://www.diveintopython.org/native_data_types/lists.html


>>> lst=["this","is","the","first","list"]
>>> lst.extend(["concatenated","with","another","list"])
>>> lst
['this', 'is', 'the', 'first', 'list', 'concatenated', 'with',
'another', 'list']

Alternative:

>>> lst=["this","is","the","first","list"]
>>> lst += ["concatenated","with","another","list"]
>>> lst
['this', 'is', 'the', 'first', 'list', 'concatenated', 'with',
'another', 'list']