<< Hide Menu
2 min read•june 18, 2024
Minna Chow
Milo Chang
Minna Chow
Milo Chang
Here's what a list looks like in AP Pseudocode.
In the AP CSP Pseudocode, index numbers start at 1, so in the example above value1 would have an index of 1, value2 an index of 2, and so on. Index values are commonly used to reference and to work with the elements in a list.
This is a key difference from Python, where the index values start at 0.
You saw in the last example how you can assign a filled-in list to a variable.
You can also assign an empty list to a variable...
For a very basic example, let's say you want to make a program that will print your to-do list out. You could manually insert values into your program to print, like so:
print ("My To-Do List is:" " Write essay", "Read Chapter 2", "Finish Math HW", "Attend Fiveable Class")
But what if you made a list instead?
to_do = ["Write essay", "Read Chapter 2", "Finish Math HW", "Attend Fiveable Class"]
print ("My To Do List is:")
print (to_do)
Now, instead of working with the data itself (the things on your to-do list), you're working with a variable, to_do, that represents the data.
There are several advantages to this. For one, it makes your code neater and easier to read. It also allows you to edit the data easily. If you wanted to print a different list in the first example, you would have to erase your code entirely and rewrite it.
By using a variable to represent the list, all you have to do is create a new list under a different name and use that variable instead.
new_to_do = ["Read Gatsby", "Practice Driving", "Go for walk"]
print ("My To Do List is:")
print (new_to_do)
Using a list also allows you to work easily with individual elements within it.
Strings are an ordered list of characters. You can navigate through them using index values, just like how you can navigate through a list using index values. We'll see this in more detail later.
By using data abstraction, you can create programs that are easier to build and maintain.
© 2024 Fiveable Inc. All rights reserved.