Python Question
Write the body of a function all_same_type(L) that consumes a
list of any type...
Python Question
Write the body of a function all_same_type(L) that consumes a
list of any type and returns true if and only if each element in
the list has the same type.
Examples:
all_same_type([]) => True
all_same_type([2, 5, 3]) => True
all_same_type([2, 'R', 4.56]) => False
Write a function
intersect(L, M)
that consumes two sorted lists of distinct integers L and M,...
Write a function
intersect(L, M)
that consumes two sorted lists of distinct integers L and M, and
returns a sorted list that contains only elements common to both
lists.
You must obey the following restrictions:
No recursion or abstract list functions,
intersect must run in O(n) where n is the combined length of
the two parameters.
Example:
intersect([3, 7, 9, 12, 14], [1, 2, 5, 7, 10, 11, 12]) => [7, 12]
Hint: As the title hints at, you are...
Python
Mutable Sequences
Implement a function reverse that takes a list as an argument
and reverses...
Python
Mutable Sequences
Implement a function reverse that takes a list as an argument
and reverses the list. You should mutate the original list, without
creating any new lists. Do NOT return anything. Do not use
any built-in list functions such as reverse().
def reverse(lst):
"""Reverses lst in place (i.e. doesn't
create new lists).
>>> L = [1, 2, 3,
4]
>>>
reverse(L)
>>> L
[4, 3, 2, 1]
"""
Complete following function which receives an array of integers
and the length of the array, and...
Complete following function which receives an array of integers
and the length of the array, and then returns the sum of all the
positive numbers in the array. For example, if an array that is
passed to this function contains following numbers: -1, 2, 0, 3, 4,
-3, 0, 2, 0, and then the return value of the function should be
11. Will this function be working correctly? Yes or No?
int sumPositive(int a[],int length)
{
int s=0;
for(int...
Write a function called odd_rms that returns orms, which is the
square root of the mean...
Write a function called odd_rms that returns orms, which is the
square root of the mean of the squares of the first nn positive odd
integers, where nn is a positive integer and is the only input
argument. For example, if nn is 3, your function needs to compute
and return the square root of the average of the numbers 1, 9, and
25. You may use built-in functions including, for example, sum and
sqrt, except for the built-in function...
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 ...
using dr.racket programing language
If we write a function that tests whether a list contains only...
using dr.racket programing language
If we write a function that tests whether a list contains only
strings, odd numbers, or even numbers, you will notice that the
code that iterates through the list stays the same, with the only
change being the predicate function that checks for the desired
list element. If we were to write a new function for each of the
tests listed above, it would be more error-prone and an example of
bad abstraction. We could write...
Python: Complete the function create_bfs_graph using
python. Do not use any libraries
def create_bfs_graph():
"""
Initializes...
Python: Complete the function create_bfs_graph using
python. Do not use any libraries
def create_bfs_graph():
"""
Initializes the undirected graph from the lecture
Uses the add_edge method
Returns Graph object of the lecture graph
Example use:
>>> ex_graph = create_bfs_graph()
>>> [x in ex_graph.children_of('Jared') for x in ['John',
'Helena', 'Donald', 'Paul']]
[False, False, True, True]
>>> ex_graph = create_bfs_graph()
>>> [x in ex_graph.children_of('Helena') for x in ['John',
'Helena', 'Donald', 'Paul']]
[True, False, False, True]
"""
# DON'T CHANGE ANYTHING...