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.
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*****
Get Answers For Free
Most questions answered within 1 hours.