Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 1.82 KB

PNadel-ManipulatingLists.md

File metadata and controls

14 lines (10 loc) · 1.82 KB

Manipulating Lists

What is a list?

A list is one of three types of data structures within Python. As opposed to tuples and dictionaries, lists are a changeable and one dimensional structure that can store data. In other languages it may be called an array; however the function is the same.

An example.

I first began my exploration into lists and list methods in Python by creating a list. To do so, I created a variable called, "TopFiveGameCubeGames" and assigned to it a list of strings. I chose string because are easily manipulated in Python and can simply encode complex data. This is the first thing to understand about the theory of lists in Python: they are data structures. This means they hold and structure data in a particular way. Lists hold values that can be changed (mutable) and that are accessible.

After I created my list, I began to experiment with the index of the list. Here I printed out a member of the list, a slice of the list and the number of members in that list.

Last I defined a method that would change the value of one of the members of the list. the changeGames function takes two parameters, the index number of the game one wants to get rid of and the name of the new game. With this function I was able to generate a new list very easily, without repeating any code.

All of these capabilities can be easily converted on to the CPX. For example, instead of strings, one can use light colors or sounds on the CPX to have it run through a variety of either of these in a specific order. In Mu, I began by creating a list called "colors" in the same way I created the "TopFiveGameCubeGames" list. I was then able to manipulate the data in the list as I would have if the entries were just strings.

Video.

Check out the video on Loom.