Python help
Using any sorting algothrim create only one function def sortstring(filename): that takes in a file which has a bunch of sentences, each line of sentence consting of different length. Sort the setences from the lower length senteces to the highest length sentence. Print it after ( DON'T USE ANY SORTING BULT-IN FUNCTION ).
Note: Keep note of time complexity as it should be able to run few 10,000 lines of sentences in few seconds.
Step 1: Open the file in read mode and store it as as a list of lines by splitting the content into lines.
Step 2: Create a list of tuples, where each tuple contains the sentence and its length.
Step 3: Sort the tuples using selection sort algorithm based on the length of sentences.
Step 4: Display the sentence corresponding to each tuple in sorted order.
Step by stepSolved in 4 steps with 3 images
- Pythonarrow_forwardUse python when completing the question: Write a function interleaved that accepts two sorted sequences of numbers and returns a sorted sequence of all numbers obtained by interleaving the two sequences. Guidelines: each argument is either a list or a range assume that each argument is sorted in non-decreasing order (goes up or stays the same, never goes down) you are not allowed to use sort or sorted (or any other form of sorting) in your solution you must interleave by iterating over the two sequences simultaneously, choosing the smallest current number from each sequence. Output: >>> interleaved( [-7, -2, -1], [-4, 0, 4, 8]) [-7, -4, -2, -1, 0, 4, 8] >>> interleaved( [-4, 0, 4, 8], [-7, -2, -1]) [-7, -4, -2, -1, 0, 4, 8] >>> interleaved( [-8, 4, 4, 5, 6, 6, 6, 9, 9], [-6, -2, 3, 4, 4, 5, 6, 7, 8]) [-8, -6, -2, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9] >>> interleaved( [-3, -2, 0, 2, 2, 2, 3, 3, 3], [-3, -2, 2, 3]) [-3, -3, -2, -2, 0,…arrow_forwardMake new code pleasearrow_forward
- Python code please help, indentation would be greatly appreciatedarrow_forwardpython exercise: Write a Python function called get_top_students that takes the list of dictionaries as input and returns a dictionary containing the name and GPA of the top two students in the list. Each dictionary has the following keys: "name", "age", "major", and "gpa".arrow_forwardQuestion in image Please explain the algorithm with the answer. Python programmingarrow_forward
- Prompt: In Python language, write a function that applies the logistic sigmoid function to all elements of a NumPy array. Code: import numpy as np import math import matplotlib.pyplot as plt import pandas as pd def sigmoid(inputArray): modifiedArray = np.zeros(len(inputArray)) #YOUR CODE HERE: return(modifiedArray) def test(): inputs = np.arange(-100, 100, 0.5) outputs = sigmoid(inputs) plt.figure(1) plt.plot(inputs) plt.title('Input') plt.xlabel('Index') plt.ylabel('Value') plt.show() plt.figure(2) plt.plot(outputs,'Black') plt.title('Output') plt.xlabel('Index') plt.ylabel('Value') plt.show() test()arrow_forwardProgramming language is latest version of pythonarrow_forwardNeed help with this short python questionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education