Question

In: Computer Science

The elements of the list are going to be strings, and will be in order of...

The elements of the list are going to be strings, and will be in order of strictly increasing or decreasing length. Some examples of lists in strictly increasing length order are [“pan”, “banana”,”xylophone”], and [“kayn”, “swain”, “morgana”].  

Function Name: fix_string_list

Parameter:

data - A list with 3 elements (that are all lowercase strings) that is either in order of strictly increasing or decreasing length.

Return: A list with the same 3 elements as the parameter that is in order of strictly increasing length.

Description:

Given a list of 3 strings that may be in order of either strictly increasing or decreasing length, return a list of 3 strings that are in order of strictly increasing length.

Examples:

Parameter: [“aloe”,”zebra”,”magnesium”]

Returns: [“aloe”,”zebra”,”magnesium”]

Parameter: [“Hydrogen”, “Carbon”, “Iron”]

Returns: [“Iron”,”Carbon”,”Hydrogen”]

Solutions

Expert Solution

PROGRAMMING LANGUAGE - PYTHON3

CODE -

def fix_string_list(data):
# Returning the reverse of the list if the strings are in order of strictly decreasing length
if len(data[0]) > len(data[1]):
return data[::-1]
# Returning the original list if the strings are in order of strictly increasing length
else:
return data

SCREENSHOT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

You are provided with an array of Strings and a list of Strings. Sort the elements...
You are provided with an array of Strings and a list of Strings. Sort the elements (1) in natural order, (2) in reverse natural order and (3) by the length of each String. You can fill in the details by using the following stub file: import java.util.Arrays; import java.util.Collections; import java.util.List; public class Midterm01 { public static void main(String[] args) { String[] arrayOfCities = { "Atlanta", "Savannah", "New York", "Dallas", "Rio" }; List<String> listOfCities = Arrays.asList("Atlanta", "Savannah", "New York", "Dallas",...
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for...
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for string in strings: st = "f'" + string + ": {" + string + "}'" print_stmt = 'print(' + st + ', end="; ")' # Uncomment the following print statement to see the statement to be executed. # Each will appear on a separate line. # print(f'\n{print_stmt}') exec(print_stmt) print() print_lv(['list(r)', 'r[-2:3:-1]', 'list(r[-2:3:-1])']) OUTPUT: list(r): [10, 13, 16, 19, 22, 25, 28, 31, 34, 37];...
1. List in proper order the different elements of providing post-mortem care (in detail).
1. List in proper order the different elements of providing post-mortem care (in detail).
1. List in proper order the different elements of providing post-mortem care (in detail).
1. List in proper order the different elements of providing post-mortem care (in detail).
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings...
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings will each be ONE character and will represent a nucleotide. The list will be a nested int list representing a 4x4 score matrix. This function will return the value (int) from the nested int list at the location of the two referenced nucleotides. a. An example call to calculate_score would be calculate_score(“A”, “T”, score_matrix). If we look at the alignment score table in the...
List the following elements in order of highest electronegativity to lowest: silicon, sulphur, argon, chlorine. (2...
List the following elements in order of highest electronegativity to lowest: silicon, sulphur, argon, chlorine. Answer the following questions about water: (10 marks total) In a single molecule of water (H2O), what kind(s) of bonds(s) are present? Explain how these bonds contribute to the high surface tension of water. Explain why water has a high specific heat and explain why this is important to life. A baking soda solution has a pH of 8. (5 marks total) Is it acidic,...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings,...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings, and improve your skills with for loops. The methods you will write will be part of a short trivia game, feel free to try it out after you finish.   import java.util.Scanner; public class Trivia { //TODO: isLeapYear //TODO: isPrime //TODO: aWord //TODO: reverse public static void main(String[] args){ Scanner answers = new Scanner(System.in); int score = 0; System.out.println("What year is a Leap Year?"); //...
Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
Write a program in C++ that will make changes in the list of strings by modifying...
Write a program in C++ that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and...
def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]: """Return a list of strings representing whether this year's...
def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]: """Return a list of strings representing whether this year's temperatures from temps_now are warmer than past temperatures in temps_then. The resulting list should contain "Warmer" at the indexes where this year's temperature is warmer, and "Not Warmer" at the indexes where the past year was warmer, or there is a tie. Precondition: len(temps_then) == len(temps_now) >>> warmer_year([10], [11]) ['Warmer'] >>> warmer_year([26, 27, 27, 28], [25, 28, 27, 30]) ['Not Warmer', 'Warmer', 'Not Warmer',...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT