Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11, Problem 5PE
Program Plan Intro
Python functions
Program plan:
- Define the function “count(myList,x)”,
- Returns the count of the given “x” value.
- Define the function “isin(myList,x)”,
- Returns “True”, if the value “x” is present in the list.
- Define the function “index(myList,x)”,
- Returns the index or position of the given “x” value.
- Define the function “reverse(myList)”,
- Return a new list consists of the elements which are reversed.
- Define the function “sort(myList)”,
- Return a new list consists of the elements which are sorted.
- Define the function “main()”,
- Create a list “myList” with the elements.
- Assign the value of “x”.
- Print the value return from “count(myList,x)”.
- Print the value return from “isin(myList,x)”.
- Print the value return from “index(myList,x)”.
- Print the value return from “reverse(myList)”.
- Print the value return from “sort(myList)”.
- Call the “main()” function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a Python recursive sum function that can sum the content of a list, tuple, set, and dictionary.
Do no use any built-in function!!!!
thank you, IN PYTHON!!!
the language is C++, please take a screenshot of your output.
(Recursive binary search) The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version of the binary search algorithm. Also, write a version of the sequential search algorithm that can be applied to sorted lists. Add this operation to the class
orderedArrayListType for array-based lists. Moreover, write a test program to test your algorithm.
Write a function in a racket code that takes as input a list of elements and returns a list with elements and their position after. For example, if the input to the function is (list ’a ’b ’c) then it will return (list a 1 b 2 c 3). Make sure to use recursion
Chapter 11 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 11 - Prob. 1TFCh. 11 - Prob. 2TFCh. 11 - Prob. 3TFCh. 11 - Prob. 4TFCh. 11 - Prob. 5TFCh. 11 - Prob. 6TFCh. 11 - Prob. 7TFCh. 11 - Prob. 8TFCh. 11 - Prob. 9TFCh. 11 - Prob. 1MC
Ch. 11 - Prob. 2MCCh. 11 - Prob. 3MCCh. 11 - Prob. 4MCCh. 11 - Prob. 5MCCh. 11 - Prob. 6MCCh. 11 - Prob. 7MCCh. 11 - Prob. 8MCCh. 11 - Prob. 9MCCh. 11 - Prob. 10MCCh. 11 - Prob. 1DCh. 11 - Prob. 2DCh. 11 - Prob. 1PECh. 11 - Prob. 2PECh. 11 - Prob. 3PECh. 11 - Prob. 5PECh. 11 - Prob. 6PECh. 11 - Prob. 7PECh. 11 - Prob. 8PECh. 11 - Prob. 9PECh. 11 - Prob. 10PECh. 11 - Prob. 11PECh. 11 - Prob. 12PECh. 11 - Prob. 15PECh. 11 - Prob. 16PECh. 11 - Prob. 18PECh. 11 - Prob. 19PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Code in python Use the fact that either the first element of a list is the largest or the largest is somewhere in the rest of the list to get a recursive function for computing the maximum element in a list. DO NOT use the max built in functionarrow_forwardWrite a recursive Python function named initList to create a list containing the values from 0 to n-1. • The function takes two parameters, a reference to the list and an integer which is the value n. In the main program you must: - initialize a list (L = []) - call the recursive function initList with this list L, to modify it - and, ask the user to enter the value n from the keyboardarrow_forwardWrite a Python function `removeDuplicates(myList)` that removes duplicate values from a list. While the algorithm for this problem might seem trivial, its implementation is not. In general, it is not advisable to modify a list while you are iterating on it, as in the following pseudo-code: for element in myList: if <condition>: <remove element(s) from myList> # recipe for disasterarrow_forward
- write a Python function that takes in a list of integers (elements), checks whether the list is sorted or not, and returns True of False accordingly. You MUST provide the most efficient algorithm in terms of its time and space complexity. What is the time and space complexity of your algorithm/function? def is_sorted(my_list)arrow_forwardCode in python Use the fact that either the first element of a list is the largest or the largest is somewhere in the rest of the list to get a recursive function for computing the maximum element in a list. DO NOT use the max built in function def maximum(L): """ returns the largest element in a non-empty list L."""arrow_forwardWrite a recursive function in Python which should take a nested/embedded list and return us the number of string elements present in it (also counting the strings present in inner lists). Sample calls are shown below; >>> countstr([10,'abc',20,'hello']) 2 >>> countstr([10,'abc',2,'20']) 2 >>> countstr([10,'abc',20,['20','fahad',100], None, 10.5]) 3arrow_forward
- write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Note (Your function MUST NOT do more than one pass on the list., you are not allowed to use built-in min and max functions.) What is the time complexity of your function (i.e., Big-oh)? max, min = find_max_min(my_list):arrow_forwardThe Binary Search algorithm works by testing a mid-point, then eliminating half of the list. In this exercise, you are going to take our binary search algorithm and add print statements so that you can track how the search executes. Inside of the recursive binary search function, add print statements to print out the starting, ending, and midpoint values each time. Then as you test a value, print out the results, either too high, too low, or a match. Sample Output Starting value: 0 Ending value: 9 Testing midpoint value: 4 Too high! Starting value: 0 Ending value: 3 Testing midpoint value: 1 Too low! Starting value: 2 Ending value: 3 Testing midpoint value: 2 Match!arrow_forwardBelow is a Python function definition for a linear search of a list lst for element. It returns the first index at which element can be found in the list (or None) if element is not in the list. def linearSearch(lst, element): i = 0 for item in lst: if element == item: return i else: i += 1 return None Write a similar MATLAB function linearSearch.m. Your MATLAB function should take as parameters an unsorted list of non-negative integers, and an integer value, and returns the index where that value is first located in the list. (No argument testing is required.) Unlike the Python code which returns None if the value is not in the array, your MATLAB function should return the value -1 if the value is not found.arrow_forward
- python code Write a recursive function such that, given a list of intergers (say v) and an integer value (say x), the function returns resulting subset if there is a subset of intergers in v that sum up to x. Otherwise the function returns an empty list; Also write a sample code that runs this function using an example list and value x, and state the expected resultarrow_forwardhow to convert this python function to java code ? def random_list(max_int, min, size, do_sort=False): arr = [random.randint(min, max_int) for i in range(size)] if do_sort: arr.sort() return arrarrow_forwardimplement QuickSort of ints that sorts the numbers in the non-decreasing order and in c language Implement the rearrange function used for QuickSort using the O(n) time algorithm with two pointers. The function gets as input an array, and index of the pivot. The function rearranges the array, and returns the index of the pivot after the rearrangement. please write form as: int rearrange(int* A, int n, int pivot_index); 2, Implement the QuickSort algorithm. For n<=2 the algorithm just sorts the (small) array (smaller number first). - For n>=3 the algorithm uses the rearrange function with the pivot chosen to be the median of A[0], A[n/2], A[n-1]. write as form: void quick_sort(int* A, int n);arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education