15. Exercises

Exercise 01

Find the last element of a list.

* (my-last '(a b c d))
(D)

Solution

Exercise 02

Find the last and second-to-last element of a list.

* (my-but-last '(a b c d))
(C D)

Solution

Exercise 03

Find an element by its position, with 1 being the first element.

* (element-at '(a b c d e) 3)
C

Solution

Exercise 04

Calculate the number of elements in a list.

* (my-length '(a b c d e))
5

Solution

Exercise 05

Reverse a list.

* (my-reverse '(a b c d e))
(E D C B A)

Solution

Exercise 06

Tell whether a list is a palindrome (it reads the same from left to right as from right to left).

* (palindromep '(a b c b a))
T

The letter p at the end of the function name indicates that it returns a boolean value (true/false).

Solution

Exercise 07

Flatten a list. To do this you will need to traverse each list recursively, replacing it with an element.

* (my-flatten '(a (b (c d) e)))
(A B C D E)

Solution

Exercise 08

Remove consecutive duplicate elements from the list. If a list contains repeated elements, they should be replaced with a single copy of the element. The order of the elements should not be changed.

* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

The HTML over WebSockets approach simplifies single-page application (SPA) development and lets you bypass learning a JavaScript rendering framework such as React, Vue, or Angular, moving the logic to Python. This web application development book provides you with all the Django tools you need to simplify your developments with real-time results.

Buy the book

Help me keep writing

Every coffee gives me a push toward the next article.

Comments

There are no comments yet.