Question

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]]. Your answer should be a single line of Python code. Hint: Use list comprehension in your lambda expression.

Answer #1

**code:
**

**output:**

**raw_code:**

#given list

L = [[1,-1,2],[-1,-2,-3],[3,2],[-5,0,5,10]]

#using map to create a list of all non-negative of each list of
L

p = list(map(lambda x : [i for i in x if i>=0],L))

#printing result

print(p)

*****do comment for queries and rate me
up*******

Write a function count_div5(nested_list) that takes in a
list of lists of integers, and returns a list of integers
representing how many integers in each sublist of the original were
divisible by 5.
Examples:
>>> count_div5([[5, 3, 25, 4], [46, 7], [5, 10,
15]])
[2, 0, 3]
>>> count_div5([])
[]
>>> count_div5([[-20, 10, 2, 4, 5], [], [5],
[8, 25, 10], [6]])
[3, 0, 1, 2, 0]

Define a nested list type in OCaml where a node is either an
element, or a list of nodes. (That is, write the OCaml code for
this new data type.) You may use the built-in data type
list as part of your definition.

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

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

In Python language:
Create a function that takes as input two numbers, m and n,
m<n, and returns an m×n list-of-list-of-numbers. Each element of
the outer list will be a list of consecutive integers, beginning
with 1 and ending with n−1. If you're feeling bold, try to use list
comprehension.

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

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

# Python
Given the list values = [], write code that fills the list with
each set of numbers below. Note: use loops if it is necessary
1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
1 4 9 16 25 36 49 64 81 100
0 0 0 0 0 0 0 0 0 0
1 4 9 16 9 7 4 9 11
0 1 0...

You have been given the following lists of Color and their
specific codes:
Colors =
['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’]
Codes = [97,17,19,128,66,111,231,00]
1. Using codeDict, find the score for 'Nocolor'.
2. Add a code of 333 for 'Nocolor'.
3. Create a sorted list of all the codes in codeDict.
4. Update the name for 'Nocolor' to be ‘white’
5. White was not a part of original colors list so, just Delete
it and its code from codeDict.
USE PYTHON CONSOLE AND SUBMIT THE...

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 31 minutes ago

asked 57 minutes ago

asked 57 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago