Question

In Python:

Sublist of list A is defined as a list whose elements are all from list A. For example, suppose list A = [0, 1, 2, 3, 4, 5, 6], its has many sublists and one of them is [0, 1, 3] because elements 0, 1 and 3 are all contained in list A.

Define a function named returnComplement that accepts two integer lists as the parameter (one of the list is the sublist of the other). Suppose names of these two parameters are A and B, and list B is a sublist of list A. Your function should return a list containing elements that are in list A but not in list B. Test your function in the main. For example, suppose A = [0, 1, 2, 3, 4, 5, 6] and B = [0, 1, 3], then your function should return list [2, 4, 5, 6].

Answer #1

**Python code pasted below.**

#function definition

def returnComplement(list1,list2):

#convert both list1 and list2 to set

set1=set(list1)

set2=set(list2)

#apply the set difference to get the complement

set1.difference_update(set2)

#convert the result back to list

result=list(set1)

return result

#main program

#function calling

print(returnComplement([0,1,2,3,4,5,6],[0,1,3]))

**Python code in IDLE pasted for better understanding of
the indent.**

**Output Screen**

Implement in python a function avg_val(lst), which returns the
average
value of the elements in list.
For example, given a list lst: [19, 2, 20, 1, 0, 18], the
function
should return 10.
The name of the method should be avg_val and the method should take
one parameter which is the list of values to test. Here is an
example call to the function
print(avg_val([19, 2, 20, 1, 0, 18]))

Write a Python function that takes two parameters: the first a
list strings and the second a single string. The function should
return True or False depending on whether the string is in the list
or not. For example, if the list contains eggs, milk, bananas, and
the second parameter is pumpkin, the function should return
False.

Write a Python function that takes two parameters: the first a
list of strings and the second a single string. The function should
return True or False depending on whether the string is in the list
or not. For example, if the list contains eggs, milk, bananas, and
the second parameter is pumpkin, the function should return False.
Thank you.

Write a Python function that takes two parameters: the first a
list of strings and the second a single string. The function should
return True or False depending on whether the string is in the list
or not. For example, if the list contains eggs, milk, bananas, and
the second parameter is pumpkin, the function should return False.
Thank you.

Write a Python function that takes two parameters: the first a
list of strings and the second a single string. The function should
return True or False depending on whether the string is in the list
or not. For example, if the list contains eggs, milk, bananas, and
the second parameter is pumpkin, the function should return False.
Thank you.

Write the function most_factors(numbers) that returns the
integer from the list numbers that has the most factors (divisors
without remainder). For example:
>>> most_factors([5,10,16,20,25])
20 # because 20 has the most factors of any of these numbers
# 6 factors, i.e., [1, 2, 4, 5, 10, 20]
>>> most_factors([1, 2, 3, 4, 5])
4 # because 4 has the most factors of any of these numbers
# 3 factors, i.e., [1, 2, 4]
Hints:
For each element in numbers, call...

Suppose L is a list of lists, where each element of L is a list
of integers. Use the map built-in function with a lambda expression
to create a list P, where each element of P is a list of all
non-negative integers in each list of L. For example, if L is the
list [[1, -1, 2], [-1, -2, -3], [3, 2], [-5, 0, 5, 10]], then P is
the list [[1, 2], [], [3, 2], [0, 5, 10]]....

IN ML(NOT PYTHON)
Write a function dupList of type 'a list -> 'a list whose
output list is the same as the input list but with each element of
the input list repeated twice in a row. For example, if the input
is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If
the input list [], the output list should be [].
Do not use explicit recursion but use one of the fold functions....

[Python] Write a function named "total_population" that takes a
string then a list as parameters where the string represents the
name of a CSV file containing city data in the format
"CountryCode,CityName,Region,Population,Latitude,Longitude" and the
second parameter is a list where each element is itself a list
containing 3 strings as elements representing the CountryCode,
CityName, and Region in this order. Return the total population of
all cities in the list. Note that the city must match the country,
name, and...

python 3
For this exercise you are to implement the function poly_iter in
the array-backed list class, which, when called with positive
integer parameters a, b, c, returns an iterator over the values in
the underlying list at indexes a*i2+b*i+c, for i=0, 1,
2, ...
E.g., given an array-backed list lst containing the elements [0,
1, 2, 3, 4, ..., 98, 99], the following code:
for x in lst.poly_iter(2, 3, 4):
print(x)
will produce the output:
4
9
18
31...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 2 minutes ago

asked 57 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago