Question
Help with this lab please! 4 functions: A one-liner with two asserts Another one-liner, with three asserts Another one-liner, though could be broken up more.
Help with this lab please!
4 functions:
A one-liner with two asserts
Another one-liner, with three asserts
Another one-liner, though could be broken up more. Has one assert.
A function with 3 asserts
0. Set up file named slicing.py
You know the drill at this point. This lab is in a file named slicing.py
1. Implement get_first() (1 point)
Write a function named get_first() that takes in a list and returns the first value in the list.
For example, if the list is ["apples", "bananas", "cherries"], then the output should be apples.
2. Implement get_last() (1 point)
Write a function named get_last() that takes in a list and returns the last value in the list.
For example, if the list is ["apples", "bananas", "cherries"], then the output should be cherries. If the list is ["apples", "bananas", "cherries", "dates"], then the output should be dates.
3. Implement get_all_but_first_and_last()
Write a function named get_all_but_first_and_last() that takes in a list and returns a sublist that is identical to the original list EXCEPT it is missing the first and last values.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["bananas", "cherries", "dates"].
Slicing time! When slicing, you need to specify a range of indices. Remember that the second index (the stop index) is NOT included in the range.
4. Implement get_all_but_first() (1 point)
Write a function named get_all_but_first() that takes in a list and returns a sublist that is identical to the original list EXCEPT it is missing the first value.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["bananas", "cherries", "dates", "eggplant"].
5. Implement get_all_but_last() (1 point)
Write a function named get_all_but_last() that takes in a list and returns a sublist that is identical to the original list EXCEPT it is missing the last value.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["apples", "bananas", "cherries", "dates"].
6. Implement get_indices_1_4_7 (1 point)
Write a function named get_indices_1_4_7() that takes in a list and returns a sublist with the values at indices 1, 4, and 7.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant", "figs", "grapes", "honeydew", "icacina"], then the output should be ["bananas", "eggplant", "honeydew"].
You may assume that the list has at least 8 elements (so indices 1, 4, and 7 all have elements).
7. Implement get_odd_indices() (1 point)
Write a function named get_odd_indices() that takes in a list and returns a sublist with all values in the odd indices of the original list.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["bananas", "dates"].
8. Implement get_even_indices (1 point)
Write a function named get_even_indices() that takes in a list and returns a sublist with all values in the even indices of the original list.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["apples", "cherries", "eggplant"].
9. Implement get_all_but_first_and_last_reversed() (1 point)
Write a function named get_all_but_first_and_last_reversed() that takes in a list and returns a sublist that is identical to the original list EXCEPT it is missing the first and last values AND it is in reverse order.
For example, if the list is ["apples", "bananas", "cherries", "dates", "eggplant"], then the output should be ["dates", "cherries", "bananas"].
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started