Chapter folders renamed

This commit is contained in:
Karan Solanki
2021-08-13 11:44:51 +05:30
parent d9f3f5b159
commit 1eb709f83a
211 changed files with 0 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
# filter1.py to get even numbers from a list
def is_even(num):
return (num % 2 == 0)
mylist = [1, 2, 3, 4, 5,6,7,8,9]
new_list = list(filter(is_even, mylist))
print(new_list)
+8
View File
@@ -0,0 +1,8 @@
# filter1.py to get even numbers from a list
def is_dublicate(item):
return not(item in mylist)
mylist = ["Orange","Apple", "Banana", "Peach", "Banana"]
new_list = list(filter(is_dublicate, mylist))
print(new_list)
+14
View File
@@ -0,0 +1,14 @@
# filter1.py to get even numbers from a list
def is_even(num):
return (num % 2 == 0)
def contains_e(name):
return 'e' in name
mylist1 = [1, 2, 3, 4, 5,6,7,8,9]
mylist2 = ["Orange","Apple", "Banana", "Peach", "Banana"]
new_list1 = list(filter(is_even, mylist1))
new_list2 = list(filter(contains_e, mylist2))
print(new_list1)
print(new_list2)
+10
View File
@@ -0,0 +1,10 @@
#map1.py to get sqauare of each item in a list
mylist = [1, 2, 3, 4, 5]
new_list = []
for item in mylist:
square = item*item
new_list.append(square)
print(new_list)
+8
View File
@@ -0,0 +1,8 @@
# map2.py to get square of each item in a list
def square(num):
return num * num
mylist = [1, 2, 3, 4, 5]
new_list = list(map(square, mylist))
print(new_list)
+9
View File
@@ -0,0 +1,9 @@
# map3.py to get product of corresponding item in the two lists
def product(num1, num2):
return num1 * num2
mylist1 = [1, 2, 3, 4, 5]
mylist2 = [6, 7, 8, 9]
new_list = list(map(product, mylist1, mylist2))
print(new_list)
+9
View File
@@ -0,0 +1,9 @@
# reduce1.py to get sum of numbers from a list
from functools import reduce
def seq_sum(num1, num2):
return num1+num2
mylist = [1, 2, 3, 4, 5]
result = reduce(seq_sum, mylist, 10)
print(result)