πŸ”’ Lists!

Learning Targets

I can create, modify, and access lists in SNAP.

Do Now (on paper)

Write an algorithm to reverse the order of any sentence.
For example, your algorithm would make the Do Now turn into:

β€œSentence a of order the reverse to algorithm an write.”

Pseudocode

sentence = word_1 + word_2 + word_3 + … + word_n

ecnetnes = word_n + … + word_3 + word _ 2 + word_1

We need variables But we don’t know how many.

Variables vs. Lists

Variables store a single value in a single location. Lists store multiple values in a single location.

List Traversal

Looking at each element of a list in order and performing some operation.

ex. Say each person’s name, count the number of May birthdays, find the average GPA…

When working with lists, we need to create an index variable to keep track of position.

SNAP (and Python!) have built in split and join functions to separate lists into individual pieces of data, and to combine individual pieces of data into a list.


Let’s get some practice:

Create a new SNAP project called β€œLists.” In that project, you will create

πŸ›£ Highway Writing

Build a block to reverse the order of a sentence by word.

πŸ”„ Sdrawkcab

Build a block that reverses the order of a sentence by splitting it into a list.