-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.py
More file actions
49 lines (42 loc) · 1008 Bytes
/
Copy pathlambda.py
File metadata and controls
49 lines (42 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# area of triangle
tri = lambda base,height: (1/2)*(base*height)
print(tri(5,66))
name =[1,4,5,6]
# map function
square = list(map(lambda a: a**2,name))
print(square)
numbers = [1,3,2,5,6,6,8,9,33,44,57]
even =[]
def is_even():
for a in numbers:
if a % 2 == 1:
even.append(a)
is_even()
print(even)
lisc = []
def square():
for b in name:
c = b**2
lisc.append(c)
square()
print(lisc)
# filter function
"""solution simple"""
numbers_list = [1,3,4,5,6,9,7,8,10]
def is_even_2():
evens = []
for a in numbers_list:
if a%2 == 0:
evens.append(a)
print(evens)
is_even_2()
"""using filter and lamda"""
is_even_3 = list(filter(lambda a: a % 2 == 0, numbers_list))
print(is_even_3)
# zip function
# example list convert into tuples
user_id = ["user_1","user_2","user_3","user_4",]
user_id_names = ["Shahab","Hamza","wahahb"]
print(tuple(zip(user_id,user_id_names)))
# convert into dictionary
print(dict(zip(user_id,user_id_names))):