Question

In: Computer Science

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

Solutions

Expert Solution

Program Code Screenshot:

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

import random
#sample list be l
l=[1,2,3,4,5,6]
print("The addition is:",sum(l))#prints the sum of elements
m=1
for i in l:
m=m*i
print("The multiplication is:",m)#prints the multiplication of list elements
print(max(l))#print the largest element from list
print(min(l))#print the smallest element from list
l=list(set(l))#removes duplicates
if len(l)==0:
print("The list is empty")
else:
print("The list is not empty")

cloned_list=l[:]
print("The cloned list is:",cloned_list)


def list_of_words(l,n):
res=[]
for i in l:
if len(i)>n:
res.append(i)#append if length of word is greater than n
return res
print(list_of_words(["wordone","word"],5))

def compare_list(l1,l2):
for i in l1:
if i in l2:
return True
return False
print(compare_list([1,2,3],[3,4,5]))
l=['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
l.pop(0)
l.pop(3)#remove the elements of the specified indexes
l.pop(3)
print("The list after removing 0,4,5 indexed elements:",l)

l=[1,2,3,4,5,6]
print("The list is:",l)
for i in l:
if i%2==0:
l.remove(i)
print("After removing even numbers :",l)

l=[1,2,3,4,5,6]
print("The list is :",l)
print("The shuffled list is :",random.shuffle(l))

l1=[1,2,3,4,5,6,7]
l2=[4,5,6,7,8,9,0]
print("The difference is:")
res=[i for i in l1+l2 if i not in l1 or i not in l1]
print(res)

l=['a','b','c']
print("The string from list ",l,"is :",''.join(l))

print("The index of 'a' is :",l.index('a'))#prints the index of a


Note:

Please let me know in case of any help needed in the comments section.

Please see that as per the guidelines multiple questions can not be solved posted under a single question.

Only multiple choice type questions can be solved(Upto 4 questions). Thank you.


Related Solutions

Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file....
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18    List as Stack """ File: pyStackPostfix.py Author: JD """ # 5 7 + 6 2 -  * = 48 print("Postfix Calculator\n") stack = []              # Empty stack...
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this...
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number. Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise. Examples is_curzon(5) ➞ True 2 ** 5 + 1 =...
Write a code to find the following in a text file (Letter). language: Python (a) Find...
Write a code to find the following in a text file (Letter). language: Python (a) Find the 20 most common words (b) How many unique words are used? (c) How many words are used at least 5 times? (d) Write the 200 most common words, and their counts, to a file. text file: Look in thy glass and tell the face thou viewest, Now is the time that face should form another, Whose fresh repair if now thou not renewest,...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
Whats the code to open a text file and every line in that text file that...
Whats the code to open a text file and every line in that text file that starts with # then it should delete that line In python using .strip
I have a Python code that reads the text file, creates word list then calculates word...
I have a Python code that reads the text file, creates word list then calculates word frequency of each word. Please see below: #Open file f = open('example.txt', 'r') #list created with all words data=f.read().lower() list1=data.split() #empty dictionary d={} # Adding all elements of the list to a dictionary and assigning it's value as zero for i in set(list1):     d[i]=0 # checking and counting the values for i in list1:     for j in d.keys():        if i==j:           d[i]=d[i]+1 #Return all non-overlapping...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write a function that consists of a set of loops that run through an array and count the number of ones in it. Do the same thing using the where() function (use info(where) to find out how to use it) (in python)
This is a python file Reads information from a text file into a list of sublists....
This is a python file Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT