Tuples are very similar to arrays/lists except that they are are unchangeable or immutable.
Here are some examples of tuples:
cars = ("Honda", "GM", "Dodge", "Hyundai")
print(cars) # prints GM
print(cars[-1]) # prints last item
print(cars[1:3]) # prints index 1-3
cars = "Tesla" #updates cars
Note that lists start with square bracket while tuples start with parenthesis. Other than that, they function very similar to each other.
Take up to 5 minutes to read through each of the following tutorials:
Don't worry too much about all the fancy functions/operations you'll read there. Most of fancy operations are not that often used and you can always look up the syntaxes later when you need them.
Given cars = ("Honda", "GM", "Dodge", "Hyundai"), complete these five functions:
- convertTupleToList(tuple) - takes a tuple and returns a list with the same content, without using the list() function.
- returnSecondToLast(tuple) - returns the 2nd to last value in the tuple
- checkLength(tuple, x) - takes a tuple and returns how many items in the tuple have string length greater than x
- tupleJoin(tuple, tuple) - takes two tuples and returns a new tuple where two tuples are joined as a single tuple
- tupleCount(tuple, char) - returns how many times the character showed up in the tuple.
Please look at the test cases to learn more about the expected behavior of these 5 methods.