solved in python please Objective: Perform the basic List tasks: intersection, complement and merge main.py prompts for

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

solved in python please Objective: Perform the basic List tasks: intersection, complement and merge main.py prompts for

Post by answerhappygod »

solved in python please
Objective: Perform the basic List tasks:
intersection, complement and merge
main.py prompts for the input of two lists
of integers. The data can be entered on a single line, separated by
spaces
Example:
Once the data has been entered the program will perform the
following operations
Task: Define the
function convert_all_to_int(list). This
function will accept a list of input like ["1", "2",
"3", "4", "5"]. Write a list
comprehension that creates a new list containing all
values converted to an int. Do not worry about validating
If the input is
convert_all_to_int(list) will return
You have been provided with
a main.py module that imports and calls
all the required functions. You may download this file to use for
testing but you are not allowed to modify it.
Examples:
If the input is
The output will be:
If the input is
The output will be
main.py:
from list_functions import intersection, complement, merge,
convert_all_to_int
one = input().split() # enter
numbers separated by spaces. As many as you'd like. Split into a
list
one = convert_all_to_int(one) # convert them all to
ints
two = input().split() # enter
numbers separated by spaces. As many as you'd like. Split into a
list
two = convert_all_to_int(two) # convert them all to
ints
print("Intersection =>", intersection(one, two))
# call intersection
print("Complement =>", complement(one, two))
# call complement
print("Sorted merge =>", merge(one, two))
# call merge
list_functions.py:
def intersection(a, b):
'''
Creates a new list that contains items shared in
both a and b
Duplicates are ignored and not added to the new
list
Accepts:
a (list): a list of integers
b (list): a list of integers
Returns:
data (list): a list containing items
that are in both a and b
'''
pass
def complement(a, b):
'''
Creates a new list that contains items not shared
by a and b.
Duplicates are ignored and not added to the new
list
Accepts:
a (list): a list of integers
b (list): a list of integers
Returns:
data (list): a list containing items
not shared in a and b
'''
pass
def merge(a, b):
'''
Merges two lists into a new sorted list
Duplicates are included
Accepts:
a (list): a list of integers
b (list): a list of integers
Returns:
data (list): the sorted and merged a
and b lists
'''
pass
# TO DO: Define the function convert_all_to_int
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply