Question

In: Computer Science

Download this file to your hard drive and follow the instructions in the Module 9 Assignment...

  1. Download this file to your hard drive and follow the instructions in the Module 9 Assignment (Word) document.
  2. Prepare two files for your post. The first file should be a text file containing your Python solution. The second file should contain your output file(txt).

Complete the following using Python on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples:

  1. Sum all the items in a list.
  2. Multiply all the items in a list.
  3. Get the largest number from a list.
  4. Get the smallest number from a list.
  5. Remove duplicates from a list.
  6. Check a list is empty or not.
  7. Clone or copy a list.
  8. Find the list of words that are longer than n from a given list of words.
  9. Take two lists and returns True if they have at least one common member.
  10. Print a specified list after removing the 0th, 4th and 5th elements.
    Sample List: ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
    Expected Output: ['Green', 'White', 'Black']
  11. Print the numbers of a specified list after removing even numbers from it.
  12. Shuffle and print a specified list.
  13. Get the difference between the two lists.
  14. Convert a list of characters into a string.
  15. Find the index of an item in a specified list.
  16. Append a list to the second list.
  17. Select an item randomly from a list.
  18. Find the second smallest number in a list.
  19. Find the second largest number in a list.
  20. Get unique values from a list.
  21. Get the frequency of the elements in a list.
  22. Count the number of elements in a list within a specified range.
  23. Check whether a list contains a sub list.
  24. Create a list by concatenating a given list which range goes from 1 to n.
    Sample list : ['p', 'q'], n = 5
    Sample Output : ['p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4', 'q4', 'p5', 'q5']
  25. Find common items from two lists.
  26. Change the position of every n-th value with the (n+1)th in a list.
    Sample list: [0, 1, 2, 3, 4, 5]
    Expected Output: [1, 0, 3, 2, 5, 4]
  27. Convert a list of multiple integers into a single integer.
    Sample list: [11, 33, 50]
    Expected Output: 113350
  28. Split a list based on the first character of a word.
  29. Select the odd items of a list.
  30. Insert an element before each element of a list.
  31. Print all elements of a nested lists (each list on a new line) using the print() function.
  32. Split a list every Nth element.
    Sample list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
    Expected Output: [['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
  33. Create a list with infinite elements.
  34. Concatenate elements of a list.
  35. Convert a string to a list.
  36. Replace the last element in a list with another list.
    Sample data : [1, 3, 5, 7, 9, 10], [2, 4, 6, 8]
    Expected Output: [1, 3, 5, 7, 9, 2, 4, 6, 8]
  37. Check if the n-th element exists in a given list.
  38. Find a tuple with the smallest second index value from a list of tuples.
  39. Insert a given string at the beginning of all items in a list.
    Sample list: [1,2,3,4], string: emp
    Expected output: ['emp1', 'emp2', 'emp3', 'emp4']
  40. Find the list in a list of lists whose sum of elements is the highest.
    Sample lists: [1,2,3], [4,5,6], [10,11,12], [7,8,9]
    Expected Output: [10, 11, 12]
  41. Find all the values in a list are greater than a specified number.
  42. Extend a list without append.
    Sample data: [10, 20, 30]
    [40, 50, 60]
    Expected output: [40, 50, 60, 10, 20, 30]
  43. Remove duplicates from a list of lists.
    Sample list : [[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]
    New List : [[10, 20], [30, 56, 25], [33], [40]]

Solutions

Expert Solution

We are allowed only to answer 5 questions, still I've answerd more than that.

Here are the code fo those:

import numpy as np
import copy
import random

sample_list = [1,2,3,4,1]

# Sum all the items in a list.
sum_list = sum([item for item in sample_list])

# Multiply all the items in a list.
mult_list = np.prod(sample_list)

# Get the largest number from a list.
max_item = max(sample_list)

# Get the smallest number from a list
min_list = min(sample_list)

# Remove duplicates from a list
uniq_list = list(set(sample_list))

# Check a list is empty or not
if(len(sample_list) == 0):
    status = 'Yes'
else:
    status = 'No'

# Clone or copy a list
copy_list = copy.deepcopy(sample_list)

print('Input list: ',sample_list)
print('Sum all the items in a list: ',sum_list)
print('Multiply all the items in a list: ',mult_list)
print('Largest number from a list: ',max_item)
print('\nSmallest number from a list: ',min_list)
print('Remove duplicates from a list: ',uniq_list)
print('Check a list is empty or not: ',status)
print('Clone or copy a list: ', copy_list)





sample_words = ['Hello','Dog','Happy','Aeroplane','Rocket']
sample_words2 = ['Hello','Cat','Sad','Car','Bus']

# Find the list of words that are longer than n = 5 from a given list of words.
output_list = [item for item in sample_words if len(item) > 5]

# Take two lists and returns True if they have at least one common member.
result = [True for item in sample_words if item in sample_words2]
if(len(result) != 0):
    status = 'Yes'
else:
    status = 'No'

print('Words that are longer than n = 5',output_list)
print('At least one common member: ', status)




# Print a specified list after removing the 0th, 4th and 5th elements.
Sample_word = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
index_remove = [0,4,5]  # indices to remove
output_list = [Sample_word[loop1] for loop1 in range(len(Sample_word)) if loop1 not in index_remove]

# Print the numbers of a specified list after removing even numbers from it.
odd_list = [item for item in sample_list if item % 2 != 0]

# Shuffle and print a specified list.
random.shuffle(sample_list)

print('After removing few indices: ', output_list)
print('After removing even numbers: ', odd_list)
print('After shuffling the list: ', sample_list)

Here is the ouputs:

For any doubts please comment below.


Related Solutions

Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download...
Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download the OO template for the basic battleship game, BattleshipRefactor.zip (refer below) The template has the outline of a battleship game using OO constructs. You need to add the Grid class and complete the code so that it runs correctly. At a minimum, you need to complete the Draw and DropBomb methods with code similar to the previous assignment. There will be changes due to...
1. Create a local file on your hard drive by using the NotePad editor that comes...
1. Create a local file on your hard drive by using the NotePad editor that comes with Windows or TextEdit on the MAC. Type into this file some remarks stating that you understand the FTP process. 2. Save it with the name "assign3.txt" 3. Start the FTP program. (SSH for Windows OR FileZilla for MAC) 4. Log on to electron.cs.uwindsor.ca server how do i do this on a mac computer It is intro to internet class
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
SPSS Module 5 Assignment—Independent t Test General Instructions:   In this assignment, we will be examining 2...
SPSS Module 5 Assignment—Independent t Test General Instructions:   In this assignment, we will be examining 2 Independent t tests and interpreting the results. As with previous assignments, the Aspelmeier and Pierce texts does a wonderful job of explaining how to actually run the tests in Chapter 7. Follow their instructions for interpretation of these test as you complete this assignment. Once again I have run the test and given you the SPSS output you will need to complete this assignment....
Module 07 Written Assignment - C-Diff Your written assignment for this module should be a 1-2...
Module 07 Written Assignment - C-Diff Your written assignment for this module should be a 1-2 page paper (not including title page and reference page) that describes the following: -You are caring for a patient with c-diff as part of your workload assignment. Discuss what c-diff is and how it is transmitted (how you can get it)? -What actions will you take as a nurse to protect yourself and the other patients on the unit when taking care of your...
Module 11 Written Assignment-Comprehensive Final (Nursing 1) Your written assignment for this module should be a...
Module 11 Written Assignment-Comprehensive Final (Nursing 1) Your written assignment for this module should be a 1-2 page paper (not including title page and reference page) that describes the following: 1. What did you learn from this course that you did not already know? 2. How will you apply what you learned to your patient care?
/* Assignment : Complete this javascript file according to the individual instructions given in the comments....
/* Assignment : Complete this javascript file according to the individual instructions given in the comments. */ // 1) Utilize comments to prevent the following line from executing alert('Danger!'); // 2) Assign a value of 5 to a variable named x // and print the value of x to the console // 3) Assign a value of 10 to a variable named myNum // and print the value of myNum to the console // 4) Assign the product of x...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1)...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1) Declare a variable named myName equal to your first name //Firstname is Susan // Construct a basic IF statement that prints the variable to the // console IF the length of myName is greater than 1 // 2) Copy your IF statement from above and paste it below // Change the IF statement to check if the length of myName // is greater than...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions in the syllabus and your grade will be determined through the use of the related rubric (also located in the syllabus). As the Baby Boom generation continues to retire from the labor force, the ratio of retirees to workers will continue to increase. How will this demographic change impact the Social Security program? What "solution" or "solutions" would best offset the harmful effects of...
Download the AddValueNewArray.java file, and open it in jGrasp (or a text editor of your choice)....
Download the AddValueNewArray.java file, and open it in jGrasp (or a text editor of your choice). This program behaves similarly to the AddValueToArray program from before. However, instead of modifying the array in-place, it will return a new array holding the modification. The original array does not change. For simplicity, the array used is “hard-coded” in main, though the method you write should work with any array. Example output with the command-line argument 3 is shown below: Original array: 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT