Topic Tag : #cwkpythonlists
Lists in python are simple to use and very flexible. You can store any type of data in them, and you can mix the types of data stored (although this isn’t generally a good idea). A list can be visualised as a set of numbered slots. You can store data in, and retrieve it from these slots in a number of ways
The essentials
Read, watch or listen
Essential:
Optional:
- More on lists
- Lists on youtube. This has a bit more information than you need at this point, but it will give you an idea of how much you can do with different types of list
Have a go
- Create and define a list of random numbers. Print them all out
- Loop over the list and print out each number in turn
- Calculate the sum of every number in the list
- Calculate the sum of items at indices 0,2 and 4 in the list
- Practice your user input skills by creating a loop that fills up the list with numbers for you
Don’t forget to add screenshots to your blog or post to twitter with the tag for this topic
Stretch yourself – Dictionaries
Read, watch or listen
Essential:
- Read about dictionaries or
- Listen to my dictionaries mini-podcast
Optional:
Have a go
- Copy this trinket to your own account or copy and paste into your IDE or editor
- How old is Dave? Print it out
- What is the average age of everyone on the list? Print that too.
- What is the age difference between Dave and Janet?
- Print a nicely formatted version of the list. For each person show their name and their age
Don’t forget to add screenshots to your blog or post to twitter with the tag for this topic
Challenge yourself – Nested dictionaries
Read, watch or listen
Essential:
- Read the nested list/dictionary information
Optional:
Have a go
- Copy this trinket to your own account or copy and paste into your IDE or editor
- Print each person in the top list
- How old is Dave? Print it out
- What is the average age of everyone on the list? Print that too.
- What is the age difference between Dave and Janet?
- Print a nicely formatted version of the list. For each person show their name, age, height and shoe size
Don’t forget to add screenshots to your blog or post to twitter with the tag for this topic