15. Exercises
Exercise 01
Find the last element of a list.
* (my-last '(a b c d))
(D)
Exercise 02
Find the last and second-to-last element of a list.
* (my-but-last '(a b c d))
(C D)
Exercise 03
Find an element by its position, with 1 being the first element.
* (element-at '(a b c d e) 3)
C
Exercise 04
Calculate the number of elements in a list.
* (my-length '(a b c d e))
5
Exercise 05
Reverse a list.
* (my-reverse '(a b c d e))
(E D C B A)
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
pat the end of the function name indicates that it returns a boolean value (true/false).
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)
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)
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
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 bookHelp me keep writing
Every coffee gives me a push toward the next article.
Sure, it's on me!
Comments
There are no comments yet.