Question

Suppose L is a list of lists, where each element of L is a list of...

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.

Homework Answers

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function count_div5(nested_list) that takes in a list of lists of integers, and returns a...
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...
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...
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...
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,...
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,...
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...
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...
# 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’]...
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...
4. 3323 A prime number can be divided, without a remainder, only by itself and by...
4. 3323 A prime number can be divided, without a remainder, only by itself and by 1. Write a code segment to determine if a defined positive integer N is prime. Create a list of integers from 2 to N-1. Use a loop to determine the remainder of N when dividing by each integer in the list. Set the variable result to the number of instances the remainder equals zero. If there are none, set result=0 (the number is prime)....