Problem 3 - Reordering List of Letters (25 points) a) Write the function get Lowercase (L) that takes, as input, a list
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem 3 - Reordering List of Letters (25 points) a) Write the function get Lowercase (L) that takes, as input, a list
Problem 3 – Reordering List of Letters (25 points)
a) Write the function getLowerCase(L) that takes, as input, a
list L of letters and returns another list that contains only the
upper-case letters in L in the same order as they appear in L. The
function should not modify the list L. Write another function
getUpperCase(L) which similarly returns a list with the upper-case
letters without modifying L and while maintaining their order. Note
1: Each letter is represented as a string of length 1 Note 2: You
are not allowed to use the built-in isupper and islower string
methods
b) Write a function reOrder(L) that takes a list of letters and
reorders this list such that all lower-case letters are placed in
the beginning of the list. Use the functions getLowerCase(L) and
getUpperCase(L) of the previous part inside your function. Note
that this function modifies the list itself, and keeps the relevant
order of the letters (i.e, the lower-case letters moved to the
beginning should keep their order with respect to each other).
c) Repeat part (b), but now you need to reorder the list
in-place; this means that you are not allowed to use the functions
you implemented in part (a) nor use any auxiliary list (i.e.,
cannot use a copy of L nor other lists). Call this function
reOrderInplace(L).
Problem 3 - Reordering List of Letters (25 points) a) Write the function get Lowercase (L) that takes, as input, a list L of letters and returns another list that contains only the upper-case letters in Lin the same order as they appear in L. The function should not modify the list L. Write another function getUppercase (L) which similarly returns a list with the upper-case letters without modifying L and while maintaining their order. Note 1: Each letter is represented as a string of length 1 Note 2: You are not allowed to use the built-in isupper and islower string methods b) Write a function reOrder (L) that takes a list of letters and reorders this list such that all lower-case letters are placed in the beginning of the list. Use the functions getLowerCase (L) and getUppercase (L) of the previous part inside your function. Note that this function modifies the list itself, and keeps the relevant order of the letters (i.e, the lower-case letters moved to the beginning should keep their order with respect to each other) c) Repeat part (b), but now you need to reorder the list in-place; this means that you are not allowed to use the functions you implemented in part (a) nor use any auxiliary list (.e., cannot use a copy of L nor other lists). Call this function reorder Inplace (L). Sample Tests: L1 - ['v','A', 'A 'b', 'c','d'] lower = getLowerCase(L1) upper - getUpperCase(L1) print('Lower in L1 -, lower) print("Upper in L1 = ', upper) reOrder(L1) print('ll after reOrdering - L1) L2 = [] L3 - ['A','b'] L4 = ['a','b', 'c L5 = ['a','b', 1','') reOrder Inplace(L2) reOrderInplace(L3) reOrder Inplace(L4) reOrder Inplace(L5) print('L2 after re-ordering in place = , L2) print("L3 after re-ordering in place = L3) print('L4 after re-ordering in place -', L4) print('L5 after re-ordering in place = ', L5) Output: Lower in L1 = ['v', 'b', 'c','d'] Upper in L1 - L'A', 'A', 'B'] L1 after reOrdering - I'v', 'b', 'c': 'd', 'A', 'A', 'B'] L2 after re-ordering in place = [] 13 after re-ordering in place = ('A', 'B'] L4 atter re-ordering in place - L'a', 'b', 'c','d'] LS after re-ordering in place = ['a', 'b' 'k', 'i'. 'i'. 'A'. 'M'. 'Z'. 'L'. 'F'