π’ 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.