DCIC, IV Programming with State, 23.8.2

43 views
Skip to first unread message

Danil Braun

unread,
Dec 15, 2021, 12:40:16 AM12/15/21
to Pyret Discuss

---

As in our sum_list function, we will need a variable to store the resulting
list as we build it up. The following code calls this zlist. The code also
shows how to use in to check whether a character is in a string (it also works
for checking whether an item is in a list) and how to add an element to the end
  of a list (pythin{append}).

def all_z_words(wordlist : list) -> list:
    "produce list of words from the input that contain z"
    zlist = [] // start with an empty list
    for wd in wordlist:
        if "z" in wd:
            zlist = [wd] + zlist
    return(zlist)

This code follows the structure of sum_list, in that we update the value of
zlist using an expression similar to what we would have used in Pyret.

---

First it says that the code will show how to add an element to the end of the
list and mentions(?) the append method. But in the code and in the paragraph
below you can see that 'we update the value of zlist using an expression
similar to what we would have used in Pyret'.

So what was meant here, and what needs to be fixed? The sentence in the first
paragraph or the code with the sentence in the second paragraph?
Reply all
Reply to author
Forward
0 new messages