ISF DP Computer Science

Parallel Lists #

This lab introduces parallel lists.


Syllabus Topics [SL] #

  • B2.2.2 Construct programs that apply arrays and Lists.
  • B2.4.2 Construct and trace algorithms to implement a linear search and a binary search for data retrieval.

Key Vocabulary #

WordDefinition
Parallel ListsWhen multiple lists store related data, with the elements at the same index across the lists holding matching information

What are parallel lists? #

๐Ÿ“– Here is an example of parallel lists. Notice how information at the same index, across both lists, are associated.

cities = ['Beijing', 'Tokyo', 'Seoul', 'Busan']
country = ['China', 'Japan', 'South Korea', 'South Korea']

print(f"{cities[0]} is in {country[0]}") # Beijing is in China

[0] Set up #

๐Ÿ’ป Go into your unit folder and clone your repo. Be sure to replace yourGithubUsername with your actual username.

cd ~/desktop/dpcs/unit02_data_structures
git clone https://github.com/isf-dp-cs/lab_parallel_lists_yourGithubUsername
๐Ÿ’ป In the Terminal, type the following command to open the lab folder.
cd lab_parallel_lists_yourGithubUsername

๐Ÿ’ป Enter the Poetry Shell to start the lab. As a reminder, we will run this command at the start of each lab, but only when we are inside a lab folder.

poetry shell
๐Ÿ‘พ ๐Ÿ’ฌ Exiting the poetry shell

When you want to exit the shell, you can type exit or ^D


[1] Song Query #

๐Ÿ‘€ First, take a look at song_data.py and notice the parallel arrays with song metadata.

๐Ÿ’ป Then, in query.py write 4 functions to easily query the titles_list and artists_list.

  • format_song(title, artist)
  • get_unique_artists(artists)
  • get_artist_by_title(titles, artists, search_title)
  • get_titles_by_artist(titles, artists, search_artist)

๐Ÿ’ป Use the functions to answer the questions at the bottom of the file.

โœ… Check your answers with a peer


[2] Deliverables #

โšกโœจ Once you complete the lab, be sure to complete these two steps:

๐Ÿ“‹ Update Syllabus Tracker: Go to your Syllabus Content Checklist in your Google Drive and update it accordingly.

๐Ÿ’ป Push your work to Github

  • git status
  • git add -A
  • git status
  • git commit -m “describe your code here”
  • git push
  • remote