🔢 Lists!October 20, 2016
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.”
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.
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
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.
Build a block that reverses the order of a sentence by splitting it into a list.