Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Python module Y111
More on Collections and Sequences
Exercises, examples and other material relating to training module Y111. This topic is presented on public courses Learning to program in Python, Python Programming, Intermediate Python

Lists, tuples and dictionaries are fundamental building blocks of Python. This module takes a look at some of the more advanced features of the use of these collection objects, assuming a prior knowledge of all the fundamental aspects of Python.

Related technical and longer articles
Python List, Python Tuple, Python Dictionary
User defined sorting - what is a callback?
copying an object - copy the reference

Articles and tips on this subjectupdated
3797zip in Python
Zipping has become synonymouse with compressing data in programming terms; originally the use of the word in that sense came from zipping up a bag so that a whole lot of contents were held together, but these days the compression (pushing everything into the bag) is kind of expected. Python's zip function ...
2012-07-14
 
3439Python for loops - applying a temporary second name to the same object
If you write a for loop in Python to go through each element of a list, you assign an extra (temporary) name to each member of the list while within the loop. So than any changes made to the named variable will also be changes to the object in the original list. However, that's overshaddowed / overtaken ...
2011-09-14
 
3348List slices in Python - 2 and 3 values forms, with an uplifting example
Python's lists are indexed collection objects. That means that they're rather like arrays in that you look up elements by their position numbers, and the number start at a fixed point (0 in the case of Python); they're not totally like arrays in that they are not stored at unchanging sequential memory ...
2011-07-06
 
3150Python dictionaries - mutable and immutable keys and values
Lists, Tuples, and dictionaries are the conventional collection variables in Python - but when you stop to consider it, objects and strings are collections too. All of these structures bundle together other elements (members) in various ways. In first dictionary demonstrations, we usually use strings ...
2011-02-10
 
2996Copying - duplicating data, or just adding a name? Perl and Python compared
When you copy a list in Perl, you're duplicating the data and you end up with two distinct copies ... but when you copy a list in Python, you're copying the reference so that you end up with two names for the same variable - almost like an alias. So in Perl - with two different copies - you end up with ...
2010-10-30
 
2920Sorting - naturally, or into a different order
There's a natural sort order for many things - for numbers, it's ascending, for words it's a dictionary order, for names it's by surname. But sometimes you want to sort a list of things different, or there's no provided way within a programming language to apply the natural sort to your type of thing. In ...
2010-08-20
 
2894Sorting people by their names
Please sort into order: Tom Pearce Bill Brewer Peter Gurney Peter Davy Daniel Whiddon Harry Hawk Uncle Tom Cobbley What would you do? Bill Brewer Uncle Tom Cobbley Peter Davy Peter Gurney Harry Hawk Tom Pearce Daniel Whiddon That's not a standard sort order for strings of text ... and if you've got ...
2010-07-30
 
899Python - extend v append on a list
In 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 ...
2010-06-20
 
2718Python - access to variables in the outer scope
In Python, variables are local to the block in which they're used unless declares in some other way. And that's good news, because the last thing you want in a substantial script is for data to "leak" between functions as can happen in default-accepting Perl or Lua. But there is an exception ... if ...
2010-04-13
 
1873List Comprehensions in Python
How do you perform an operation on every member of a list, producing a new list? A List Comprehension in Python is a structure in which a for loop is written within a list's square brackets. Its purpose is to allow the programmer to write short code that's used to transform each element of a source list, ...
2008-11-07
 
1869Anonymous functions (lambdas) and map in Python
Why do you name variables? So that you can use them again later. But if you don't want to use them more than once, why bother with a name at all? Most programming languages create temporary or anonymous variables within a single line, and if you've programmed almost anything, you'll have used them without ...
2008-11-04
 
1310Callbacks - a more complex code sandwich
When you write a piece of code, you're normally putting the filling into the sandwich; there's a built-in program in your computer that controls the loading and running of the code thst you've written, and there is a whole library of standard pieces of code that you call to perform the low level operations. ...
2007-08-21
 
1304Last elements in a Perl or Python list
How do we refer to the elements of a list? By index number, starting at zero and stopping one short of the number of elements in the list. So a 20 element list has element numbers 0 to 19. How can we refer to the last element, then? We could write an expression based on the length of the list - ...
2007-08-16
 
633Copying a reference, or cloning
If you copy a variable in a program, you end up with a duplicate, right? set second $first ... in Tcl second=$first ... in shell second = first ... in Python, Ruby, C and Java $second = $first ... in Perl and PHP Well - ALMOST right. For sure an assignment copies a variable, but where that variable ...
2006-06-09
 
386What is a callback?
When you write a program, you're usually providing the filling for a sandwich. At the top level, you have the operating system and the compiler or interpreter for the particular language you're using and this provides you with the mechanism to start and end your program, and for it to share the resources ...
2006-06-05
 
Examples from our training material
2dli.py   List - multiple dimensions
coldem   Collections - initial setup and reference
coplist.py   List - copy through assignment
copy_levels   alias, shallow copy and deep copy comparison
cuber   using a callback to map a list
deepcop.py   List - deep copy
dsd   Python equivalent of Schwartzian transform
fortan   A list of lists (a matrix?)
furlist.py   Further methods that run on lists - looking things up
indemo   Sorting a dictionary?
lat.py   copy reference and shallow copy
lirev.py   List - revision
namsort.py   Natural sorting of a list of strings
p162   Sample answer - module exercise
rails_dict   Sorting and subsorting into your own order
sal   Sorting in a non-standard way
sby_sname   Sorting by surname
scenario   Encapsulating changes in a function
shallowcop.py   List - shallow copy
slices   list slices - revision
uip2.py   Counting in a dictionary, and sorting
unamsort.py   Sorting of a list of strings - user routine ignoring case
Pictures
To teach Python in Manchester
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from http://www.training-notes.co.uk.
Topics covered in this module
Complex Structures.
Assignments, shallow and deep copies.
Further operations on lists.
Sorting a list - natural order and user sorts.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre. Also available is the Opentalk Forum for discussion of technical questions.


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/resources/Y111.html • PAGE BUILT: Thu Sep 18 11:03:17 2014 • BUILD SYSTEM: WomanWithCat