Welcome to the additional basic list exercises assignment! This exercise will help you further practice working with lists in Python by implementing a few more functions. Follow the instructions below to complete the assignment.
-
Fill in the Code:
- You will complete the functions provided in the
list2.py
file. - Each function has a description of what it should do. Your task is to write the code inside each function to achieve the described behavior.
- The
main()
function is already set up to call these functions with various inputs and print'OK'
when a function is correct.
- You will complete the functions provided in the
-
Function Descriptions:
- Remove_adjacent:
- Given a list of numbers, return a list where all adjacent equal elements have been reduced to a single element.
- Example:
remove_adjacent([1, 2, 2, 3])
should return[1, 2, 3]
.
- Linear_merge:
- Given two lists sorted in increasing order, create and return a merged list of all the elements in sorted order.
- Ideally, the solution should work in "linear" time, making a single pass of both lists.
- Example:
linear_merge(['aa', 'xx', 'zz'], ['bb', 'cc'])
should return['aa', 'bb', 'cc', 'xx', 'zz']
.
- Remove_adjacent:
-
Testing Your Code:
- The
main()
function includes test cases that will help you verify if your implementations are correct. - The
test()
function compares the output of your function with the expected result and prints'OK'
if they match, otherwise it prints'X'
.
- The
- Complete as many functions as you can.
- Ensure your code runs without errors.
- Submit your completed
list2.py
file by pushing your repo to GitHub and it will auto grade.
Happy coding!