Recitation: Lists (I)

Act like a computer (tracing nested loops)

What's the output of mystery(42)?

What's the output of mystery(103)?

Exercise 0

Implement the function times10(L) that returns a list containing the same elements as L, but multiplied by 10.

For example, times10([1,2,3]) should return [10,20,30].

Worked solution:

Q. What do you notice from the output?

Q. What's the bug? 🐛

Exercise 1

Find the maximum element of a list. You cannot use the builtin function max

Worked solution:

Exercise 2

You receive a list with zeros and ones corresponding to a binary number. Write the function binToDec(B) that returns the decimal representation of B.

For example, binToDec([1,1,0]) should return 6.

Exercise 3

Given a list L and element e, write the function count(L, e) that counts the number of times e occurs in L.

Exercise 4

Implement the function allTheSame(L) that returns True if all elements of list L are the same, and False otherwise.