Exercise: From List to Tuple
Let's use some of the elements of a list to make a tuple.
We'll cover the following
Problem Statement
You are given a list called my_list
. Using this list, you must create a tuple called my_tuple
. The tuple will contain the list’s first element, last element, and the length of the list, in that same order.
Sample Input
my_list = [34, 82.6, "Darth Vader", 17, "Hannibal"]
Sample Output
my_tuple = (34, "Hannibal", 5)
Coding Challenge
There are several ways of solving the problem. Flesh out the logic before moving on to the implementation.
my_list
has already been created. You only need to make my_tuple
.
If you feel stuck, feel free to check out the solution review in the next lesson.
Good luck!
Get hands-on with 1200+ tech skills courses.