Fall 2017 Python Open Lab Week 2

Week 2: October 3rd
This week we started with a brief review of the basics from week 1 and the starter kit. We continued on with Data Structures and worked through Lists, Tuples and Dictionaries. These concepts were easy to approach and we went over many practice examples on the way. Towards the end of the session, we introduced the different types of lists that one can use in Python as well as list methods. List methods, however, are quite complex and we only got through .append and .extend in great detail.
Next week we will continue with list methods!
Please comment or email us for any questions. Below is the worksheet we used for this week:
 
Python Open Lab Week II
Outline and reference:

  1. Summary from Open Lab I – Starter Kit
  2. Data Structures:

Lists:
Lists are what they seem – a list of values. Each one of them is numbered, starting from zero – the first one is numbered zero, the second 1, the third 2, etc. You can remove values from the list, and add new values to the end. Example: Your many cats’ names.
Tuples:
Tuples are just like lists, but you can’t change their values. The values that you give it first up, are the values that you are stuck with for the rest of the program. Again, each value is numbered starting from zero, for easy reference. Example: the names of the months of the year.
Dictionaries:
Dictionaries are similar to what their name suggests – a dictionary. In a dictionary, you have an ‘index’ of words, and for each of them a definition. In python, the word is called a ‘key’, and the definition a ‘value’. The values in a dictionary aren’t numbered – tare similar to what their name suggests – a dictionary. In a dictionary, you have an ‘index’ of words, and for each of them a definition. In python, the word is called a ‘key’, and the definition a ‘value’. The values in a dictionary aren’t numbered – they aren’t in any specific order, either – the key does the same thing. You can add, remove, and modify the values in dictionaries. Example: telephone book.
Lists:

  • Indexing
  • Slicing
  • List operations (concat, etc.)
  • Multiplying
  • “In” operator

*Question: Given a year, month, day, print as follows:
21st July, 1991
Methods:

  • Append
  • Extend
  • Count
  • Index
  • Insert
  • Pop
  • Remove
  • Reverse
  • Sort/Sorted