📚

All Subjects

 > 

⌨️ 

AP Comp Sci P

 > 

📱

Big Idea 3: Algorithms and Programming

Data Abstraction

2 min read•november 16, 2020

minnachow

Minna Chow


AP Computer Science Principles ⌨️

Bookmarked 2.3k • 69 resources
See Units

Lists in APCSP Pseudocode

Here's what a list looks like in AP Pseudocode.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-goG5CZLHYkZR.png?alt=media&token=593af9f4-35a5-48ac-86fa-95886dfbba9e
An element is an individual value in a list: in the example above, value1, value2, and value3 are all elements. Each element is assigned an index value, or a number representing their place in the list.
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...
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-dlh3Ow2YvS2R.png?alt=media&token=4e7047b8-2b1b-4be9-9c43-2db969b3e079
and one list to another.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-gj2UKOFPi0Cu.png?alt=media&token=1b36c419-7eff-4c7d-a238-695b5ad49819
Lists can be used to create data abstraction. Data abstraction simplifies a set of data by representing it in some general way. You can then work with that representation instead of each piece of data itself.
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, as you'll see below.
By using data abstraction, you can create programs that are easier to build and maintain.

Was this guide helpful?

Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
Hours Logo
Studying with Hours = the ultimate focus mode
Start a free study session
🔍 Are you ready for college apps?
Take this quiz and find out!
Start Quiz
Browse Study Guides By Unit
🕹Big Idea 1: Creative Development
⚙️Big Idea 2: Data
📱Big Idea 3: Algorithms and Programming
🖥Big Idea 4: Computer Systems and Networks
⌨️Big Idea 5: Impact of Computing
✏️Blogs
📝Exam Prep
Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
💪🏽 Are you ready for the AP CSP exam?
Take this quiz for a progress check on what you’ve learned this year and get a personalized study plan to grab that 5!
START QUIZ