Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
Python - extend v append on a list

Luncheon at LacockIn Python, you can extend a list and you can append to it as well.

What's the difference? If you append a list to another list, you add the new list as a single extra list to the original, thus makingthe original list just one longer with an item that is itself a list. But if you extend a list with another list, you add each element of the new list onto the original. Here's an example to show you what I mean:

>>> first = [10,20,30]
>>> second = [40,50,60]
>>> first.append([70,80,90])
>>> second.extend([100,110,120])
>>> first
[10, 20, 30, [70, 80, 90]]
>>> second
[40, 50, 60, 100, 110, 120]
>>>



Illustration - delegates come on our Python courses from near and far. For delegates who are new to the UK, we try to provide "a taste of England" too - taking lunch at a variety of interesting places. Pictured - course delegates at Lacock, about 4 miles from our training centre
(written 2006-10-20, updated 2010-06-20)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y104 - Python - Lists and Tuples
  [4027] Collections in Python - list tuple dict and string. - (2013-03-04)
  [3763] Spike solutions and refactoring - a Python example - (2012-06-13)
  [3669] Stepping through a list (or an array) in reverse order - (2012-03-23)
  [3348] List slices in Python - 2 and 3 values forms, with an uplifting example - (2011-07-06)
  [3257] All possible combinations from a list (Python) or array (Ruby) - (2011-04-23)
  [3181] Beware - a=a+b and a+=b are different - Python - (2011-02-23)
  [3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
  [2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
  [2719] Traffic lights in Python - (2010-04-13)
  [2368] Python - fresh examples of all the fundamentals - (2009-08-20)
  [2284] Strings as collections in Python - (2009-07-12)
  [2280] Creating and iterating through Python lists - (2009-07-12)
  [1789] Looking for a value in a list - Python - (2008-09-08)
  [1641] Tektronix 4010 series / Python Tuples - (2008-05-13)
  [1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
  [955] Python collections - mutable and imutable - (2006-11-29)
  [657] The ternary operator in Python - (2006-03-25)
  [383] Overloading of operators on standard objects in Python - (2005-07-19)

Y111 - Python - More on Collections and Sequences
  [3797] zip in Python - (2012-07-05)
  [3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
  [3150] Python dictionaries - mutable and immutable keys and values - (2011-01-29)
  [2920] Sorting - naturally, or into a different order - (2010-08-14)
  [2894] Sorting people by their names - (2010-07-29)
  [2718] Python - access to variables in the outer scope - (2010-04-12)
  [1873] List Comprehensions in Python - (2008-11-06)
  [1869] Anonymous functions (lambdas) and map in Python - (2008-11-04)
  [1310] Callbacks - a more complex code sandwich - (2007-08-19)
  [1304] Last elements in a Perl or Python list - (2007-08-16)
  [633] Copying a reference, or cloning - (2006-03-05)
  [386] What is a callback? - (2005-07-22)
  [61] Python is a fabulous language - (2004-09-24)


Back to
Courses at Well House Manor
Previous and next
or
Horse's mouth home
Forward to
Python - function v method
Some other Articles
Pieces of Python
Brand new hotel and training centre, Melksham
Python - listing out the contents of all variables
Python - function v method
Python - extend v append on a list
Courses at Well House Manor
Too much for the National Trust
PHP - good coding practise and sticky radio buttons
Welcome, Martin
Where quality costs less
4280 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/899_Pyth ... -list.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat