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
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....
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...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Implement a singly linked list having all unique elements with the following operations.I 0 x –...
Implement a singly linked list having all unique elements with the following operations.I 0 x – Inserts element x at the end. I 1 y x – If the element y exists, then insert element x after the element y, else insert element y before the existing element x. Assuming either the element x or the element y exists. I 2 z y x – Inserts element x in the middle of the elements z and y. The element z...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m. The Lab08 function will take in a string as input and will return an integer n as output. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'. Please note that...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT