-
Notifications
You must be signed in to change notification settings - Fork 0
/
28recursion.py
59 lines (41 loc) · 1.57 KB
/
28recursion.py
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
48
49
50
51
52
53
54
55
56
57
58
# Recursion: Recursion in the process of defining something in terms itself.
def factorial(num):
if(num ==1 or num ==0):
return 1
else:
return(num *factorial(num-1))
num = -2
print("Number:", num)
print("factorial:",factorial(num))
# Python sets: Sets are unordered collection of data. We can't acess set's elements by index, it stores in unordered manner.
# info={"Sorav",19,False, 3.2121,9.2323}
# print(info)
# 1. joining Sets:
# union() and update()
name1 = {"Sourav","dipanwita","Saptarshi","Shounak"}
name2 = {"Sourav", "Sourin","Sandip","Pratik"}
name3 = name1.union(name2) # Return a new set
print(name3)
name1.update(name2)
print(name1) # Adds item to a existing set
# intersection and intersection_update():
name1 = {"Sourav","dipanwita","Saptarshi","Shounak"}
name2 = {"Sourav", "Sourin","Sandip","Pratik"}
name3 = name1.intersection(name2) # Create a new set
print (name3)
name1.intersection_update(name2) # This method print only the item present in two sets(Common items)
print(name1)
# symmetric_difference() and symmetric_difference_update():
name1 = {"Sourav","dipanwita","Saptarshi","Shounak"}
name2 = {"Sourav", "Sourin","Sandip","Pratik"}
name3 = name1.symmetric_difference(name2)
print(name3)
name1.symmetric_difference_update(name2)
print(name1)
# difference() and difference_update():
name1 = {"Sourav","dipanwita","Saptarshi","Shounak"}
name2 = {"Sourav", "Sourin","Sandip","Pratik"}
name3 = name1.difference(name2)
print(name3)
name1.difference_update(name2)
print(name1)