Skip to content

List comprehensions page example includes functions which haven't been covered yet #2

@HuwWDay

Description

@HuwWDay

For continuity it might be worth changing the example bit of code in the final exercise of this page so it doesn't include a pre-defined function. Currently there's a block that says:

def encode(message):
    morse = []

    for letter in message:
        letter = letter.lower()
        morse_letter = letter_to_morse[letter]
        morse.append(morse_letter)

    morse_message = " ".join(morse)
    
    return morse_message


message = "SOS We have hit an iceberg and need help quickly"

encoded_message = encode(message)

This also means that in a later exercise (on writing functions page), students are prompted to write this code as a function but it has already been written as one!

Recommend changing it back to:

morse = []

for letter in message:
    letter = letter.lower()
    morse_letter = letter_to_morse[letter]
    morse.append(morse_letter)

morse_message = " ".join(morse)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions