0% found this document useful (0 votes)
6 views

Python Assignment Juhi

The document contains a Python assignment with six programming tasks. These tasks include adding values to a list, summing elements of two lists, finding the largest element in a list, creating a list of squares, filtering positive numbers from a list, and converting uppercase strings to lowercase. Each task is accompanied by sample code demonstrating the required functionality.

Uploaded by

JUHI CHOPRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Assignment Juhi

The document contains a Python assignment with six programming tasks. These tasks include adding values to a list, summing elements of two lists, finding the largest element in a list, creating a list of squares, filtering positive numbers from a list, and converting uppercase strings to lowercase. Each task is accompanied by sample code demonstrating the required functionality.

Uploaded by

JUHI CHOPRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Assignment – 4

Juhi Chopra

1.WAP that add 2 to every value in the list in python.

def add_2(x):

x+= 2 return x num_list = [1,2,3,4,5] print("Orginal list",

num_list) updated_list = list(filter(lambda x: True, map(add_2,

num_list)))

print("Updated list:", updated_list)

2. WAP to add elemts of two list and return a new list using map.

def add_list(x, y): return x + y

list1 = [1, 2, 3] list2 = [4, 5, 6] result =

list(map(add_list, list1, list2))

print(result)
3. WAP to find largest element of list using reduce function. from functools import reduce

def find_max(x, y):

if x > y:

return x

else:

return y

numbers = [10, 25, 87, 45, 67]

largest = reduce(find_max, numbers)

print("Largest element:", largest)

4. WAP using map to create list of squares of numbers in range 1 to 10.

def sq(x):

return x*x

res = list(map(sq,range(1,10)))

print(res)

5. WAP that has a list of +ve and -ve numbers create another list using filter function that
has only +ve number. def positive(x):

if x >= 0: return x list1 =

[12,3,4,-5,6,7,-8,-9,1,2] res =
list(filter(positive, list1))

print(res)

6.WAP that convert string of all uppercase character in string of lowercase character using
map.

def lower(x):

return x.lower() list1 =

["Arti", "KANWAL"] res =

list(map(lower, list1))

print(res)

You might also like