Question

Use Python to Complete the following on a single text file and submit your code and...

Use Python to Complete the following 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:

Sum all the items in a list.

Multiply all the items in a list.

Get the largest number from a list.

Get the smallest number from a list.

Remove duplicates from a list.

Check a list is empty or not.

Clone or copy a list.

Find the list of words that are longer than n from a given list of words.

Take two lists and returns True if they have at least one common member.

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']

Print the numbers of a specified list after removing even numbers from it.

Shuffle and print a specified list.

Get the difference between the two lists.

Convert a list of characters into a string.

Find the index of an item in a specified list.

Append a list to the second list.

Select an item randomly from a list.

Find the second smallest number in a list.

Find the second largest number in a list.

Get unique values from a list.

Get the frequency of the elements in a list.

Count the number of elements in a list within a specified range.

Check whether a list contains a sub list.

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']

Find common items from two lists.

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]

Convert a list of multiple integers into a single integer.
Sample list: [11, 33, 50]
Expected Output: 113350

Split a list based on the first character of a word.

Select the odd items of a list.

Insert an element before each element of a list.

Print all elements of a nested lists (each list on a new line) using the print() function.

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']]

Create a list with infinite elements.

Concatenate elements of a list.

Convert a string to a list.

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]

Check if the n-th element exists in a given list.

Find a tuple with the smallest second index value from a list of tuples.

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']

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]

Find all the values in a list are greater than a specified number.

Extend a list without append.
Sample data: [10, 20, 30]
[40, 50, 60]
Expected output: [40, 50, 60, 10, 20, 30]

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]]

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 file).

Needs to have a separate output file that shows the outputs of the code.

Homework Answers

Answer #1

PROGRAM:

Output:

Summary:

Problems based on list :

1) sum - all all elements

2) Multiply - all the element

3) largest - using max() in list

4) Smallest - using min() in list

5) Without duplicates - Convert the list to dictionary as list element key => convert back to list (or else use set())

6)empty - Check list length - if 0 empty else not empty

7)copy list - using = operator

8)check string len - len() if len()>8 display the word

9) common - check if atleast one element in list 2 return True

10) remove index 5,4,0 - using pop(index) {Remove from the larger index - if you remove from smallest the index value will change}

11)After removing even numbers (check for remainder if divided by 2

12) shuffle list - use random.shuffle

13)difference between lists- If a number not common then display

14)list to string => "".join() method ; "" =without space

15)Element at index => index() method

16) Append list1+list2

17) Random number - use random.choice()

18) second smallest - remove first smallest and then find the smallest => second smallest using min()

19) second largest - remove first largest and then find the max()

20) Unique number use set() or from dictionary

21) Frequency of elements - generate dictionary with list values as keys - Iterate and increment the count for each key

22)Number within range - check if num with range and increment count min<number<max

23) check all values of subset in the listset and return True or False

24) add the str and integer by converting the integer

25) common items - And of set of both lists  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []        //create empty list to merge the lists M and N if not M:                //if M is empty list, m = 0                //set m = 0 else: m = len(M)             //otherwise, set m = len(M) if not N:                //if N is empty list, n = 0       ...
Code in JAVA The requirements are as follows: The input will be in a text file...
Code in JAVA The requirements are as follows: The input will be in a text file whose name is given by arg[0] of main(). It will contain a fully-parenthesized infix expression containing only: "(", ")", "+", "-" and integers. Need help on the main and fixing the Queue. //Input: ( ( 1 + 2 ) - ( ( 3 - 4 ) + ( 7 - 2 ) ) ) ( ( 1 + 2 ) - ( 3 -...
Python: Working with CSV file --> How would I write a function that will return a...
Python: Working with CSV file --> How would I write a function that will return a list of lists, with the frequency and the zip code. Organize the list in decreasing order of frequency (Print the number of suppliers and the zip code for the 10 most common zip codes in the file. ) An example of three items from the 720 zip codes results in: [ ... [9, '65616'], [8, '94573'], [8, '63103'] ...]. This tells us that Branson,...
Language: C++ You're given a 1000-line text file, phoneno.txt, where each line consists of a 5-digit...
Language: C++ You're given a 1000-line text file, phoneno.txt, where each line consists of a 5-digit ID# and a phone# in the format of ###-###-####. The data were generated randomly so there might be duplicates in the IDs. You're asked to do the following by using standard library algorithms as much as possible: 1. read the file into a map which has an integer for key (ID#) and a string for value (phone#), this allows the duplicates to be removed....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
In Python write a program that prompts the user for six elements and their atomic numbers...
In Python write a program that prompts the user for six elements and their atomic numbers and stores them in a list. Each element and weight pair should also be a list. After the values have been entered, print the list as it entered. Then print the first two characters from the element names (the first character capitalized and the second in lower case) along with the atomic number, starting with the element with the lowest atomic number. You must...
Provide a complete solution to the following problem using the C++ language in a SINGLE file...
Provide a complete solution to the following problem using the C++ language in a SINGLE file with a .cpp file extension. READ THE ENTIRE QUESTION (AND THE EXAMPLE) CAREFULLY BEFORE DEVELOPING YOUR SOLUTION! Design the code for a class called Pi, which will be used to encapsulate the value of pi stored as a string. (example ONLY) "3.141592654" | |_ _ _ _| whole number portion_| |_ _ _ _ _fractional portion (9 digits) The Pi class has the following...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT