Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 21.3, Problem 21.3.5CP
Explanation of Solution
Data Structure to be used:
In order to write a program that stores the elements in a list with frequent operations to append and delete elements at the end of the list, one must use an “ArrayList” data structure...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write in Python:
Complete the calc_average() function that has an integer list parameter and returns the average value of the elements in the list as a float.
Ex: If the input list is:
1 2 3 4 5
then the returned average will be:
3.0
python help, please show all steps and include comments
Write a function largerLst() that takes a list of numbers (i.e., int or float values) as a parameter and returns a new list constructed out of it. The list returned has all the values in the parameter list that are larger than the element immediately to their right, that is, larger than their right neighbor. If the parameter list is empty or there are no values larger than their right neighbor, then the function returns an empty list. Note that the last element in the list will never be included in the list returned since it does not have a right neighbor. The function should not change the parameter list in any way. Note that a correct solution to this problem must use an indexed loop That is, one that makes a call to the range() function to generate indices into the list which are used to solve the problem (Review lecture notes 8-1). A solution that does not use an indexed loop will not be accepted. Note in particular that you…
please code in python
Create a program that uses list comprehension to take the following list and create a new list out of elements that have at least one ‘a’ character. Print out the new list.[‘Ford’, ‘Mazda’, ‘BMW’, ‘Nissan’, ‘Hyundai’, ‘Tesla’, ‘Honda’, ‘Subaru’, ‘Kia’, ‘Audi’, ‘Fiat’, ‘Bentley’, ‘Toyota’, ‘Lexus’]
Chapter 21 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
Knowledge Booster
Similar questions
- I having trouble with this prroblemarrow_forwardin phython language Create a list that consists of all the numbers between 5 and 15. Use a for or while loop. (Create an empty list first, then append the numbers to the list in each iteration of a loop.) Insert the number -5 in index position 4 Delete the number at index 9 Append the number -7 to the list Sort the list Create another list that contains the first 5 elements of the first list, deleting this elements from the first list. Print the listsarrow_forwardIn python Write program that counts the number of times an element appears in a list. you should ask the user to enter the number and continue as long as the user wish. For example, if the list is: numbers=[1,4,3,2,5,8,2,3,4,6,2,1]and we are looking for 2 , it should return 3 . If we look for 7 , it should return 0 .)arrow_forward
- python code easy way pleasearrow_forwardFocus on: Basic list operations, methods, use of functions, and good programming style. Program should be in basic python. Part 1. Write a program that does the following:1. Create a list of length N where N is a randomly selected integer between 10 and 20 andwhose elements are randomly selected integers between 0 and 19.2. Print out the list.3. Create a copy of the list. Sort the copy into decreasing order and print it.4. Report the distinct elements in the listBefore continuing with the next two parts, add a function user_input(lo, hi) to yourprogram. It should ask the user for an integer between lo and hi and return the value. Useappropriate error handling and input validation. Part 2.Write a function named how_many(a_list, a_num) that that expects a list of numbersand a number as arguments. It returns how many times the number is found in the list.If the number is not in the list, return 0. For examplehow_many( [12, 15, 16, 4, 10, 3, 5, 7, 9, 15], 15 )returns 2 And how_many( [12,…arrow_forwardA code segment is intended to transform the list utensils so that the last element of the list is moved to the beginning of the list. For example, if utensils initially contains ["fork", "spoon", "tongs", "spatula", "whisk"], it should contain ["whisk", "fork", "spoon", "tongs", "spatula"] after executing the code segment. Which of the following code segments transforms the list as intended? len + LENGTH (utensils) temp + utensils[len) REMOVE (utensils, len) APPEND (utensils, temp) A len + LENGTH(utensils) REMOVE (utensils, len) B temp + utensils[len) APPEND (utensils, temp) len + LENGTH (utensils) temp + utensils[len] REMOVE (utensils, len) INSERT (utensils, 1, temp) len + LENGTH(utensils) REMOVE (utensils, len) D temp + utensils[len] INSERT(utensils, 1, temp)arrow_forward
- Focus on: Basic list operations, methods, use of functions, and good programming style Part 1. Write a program in python that does the following: 1. Create a list of length N where N is a randomly selected integer between 10 and 20 and whose elements are randomly selected integers between 0 and 19. 2. Print out the list. 3. Create a copy of the list. Sort the copy into decreasing order and print it. 4. Report the distinct elements in the list Before continuing with the next two parts, add a function user_input(lo, hi) to your program. It should ask the user for an integer between lo and hi and return the value. Use appropriate error handling and input validation. (You should already have one of these from back in Module 05) Part 2. Write a function named how_many(a_list, a_num) that that expects a list of numbers and a number as arguments. It returns how many times the number is found in the list. If the number is not in the list, return 0. For example how_many( [12, 15, 16, 4, 10, 3,…arrow_forwardPython Help Write a function equals(a,b) that returns true when the two lists a, and b have the same elements in the same order, and false otherwise.Write main() to call the function equals(a,b)arrow_forwardWrite a statement, using pyhton language, that creates a two-dimensional list with 5 rows and 3 columns. Then write nested loops that get an integer value from the user for each element in the list.arrow_forward
- Python Programming: Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers.Sample data : 3, 5, 7, 23Output :List : ['3', ' 5', ' 7', ' 23']arrow_forwardPlease Answer this ques with showing the answer in python ( there is only 1 ques with 2 steps) Step 1: Using the list from this ques : Create this list of pets: ['teddy', 'polly', ‘jessie’, 'ghost'] Be sure to refer to the list element by its index Write the python statement whose output is: Output : Hello POLLY, you are a fine parrot! Write a python statement to add 'spot' to the list between 'teddy' and 'polly'. Print the updated list Output: ['teddy', 'spot', 'polly', 'jessie', 'ghost'] step 2: Using the updated list from the step 1 Use slicing (start,stop,step) to copy the elements ‘teddy’ and ‘jessie’ to a new list, pets_in_heaven. Print pets_in_heaven Output: ['teddy', 'jessie']arrow_forwardList comprehension. Write a Python program called list_comprehension.py that contains remove_list = [1,5,7, 9]. Create a list that is initialized by a list comprehension that contains all numbers from 0-10, but none of the numbers on the remove_list. Do not use for loop. Print the contents of the list.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