Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

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
User defined sorting - what is a callback?
Python List, Python Tuple, Python Dictionary
copying an object - copy the reference

Articles and tips on this subjectupdated
4442Mutable v Immuatble objects in Python, and the implication
In python, "everything is an object" - well, at least everything you name, and lots of standard system things too, are! Some object types are immutable. That means tha once they have been created, they cannot be modified and any code that looks like it modifies them in reallity produces a new object ...
4398Accessing variables across subroutine boundaries - Perl, Python, Java and Tcl
In a perfect programming world, code is broken into named blocks (methods, functions, subroutines, classes, procedures, commands, modules, packages etc) and data is passed around between the blocks purely as parameters and return values. And variables are local to the block in which they're used. This ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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. ...
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 - ...
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 ...
61Python is a fabulous language
I'm running a Python course this Wednesday-through-Friday and for students who have self-taught themselves just enough of a structural programming language, it's a big challenge and also an opening of a door through which a bright light shines. Even I'm still amazed by the cleanness of it all and the ...
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
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 [here].
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 Ruby, Lua, 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.

You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.info/resources/Y111.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb