forked from GariBisht/Projects_for_hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1.py
90 lines (76 loc) · 1.43 KB
/
p1.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# How to reverse a string
'''
string = "Hello, this is Arpit Garg"
print(string)
a = string.split()
c = []
print(a)
for i in a:
rev = i[::-1]
c.append(rev)
print(c)
rev_string = ' '.join(map(str, c))
print(rev_string)
'''
# Remove Repeatative Numbers from an Array(List)
'''
my_list = [1,2,3,4,5,6,7,2,3,1]
new_list = []
for i in my_list:
if i not in new_list:
new_list.append(i)
print(new_list)
'''
# Lambda Functions
'''
my_func = lambda x: x*x
print("square is :", my_func(2))
'''
# Generator Functions
'''
def gen():
yield 1
yield 2
yield 3
values = gen()
print(values.__next__()) #For values
print(values.__next__())
print("-------------")
#yield basically a type of return which is used to create generator it not get terminated after execution of a program
def gene():
n = 1
while n <=10 :
sq = n*n
yield sq
n += 1
val = gene()
for i in val:
print(i)
'''
# Multithreading
'''
from threading import *
from time import sleep
class func1(Thread):
def run(self):
for i in range(50):
print("Func1 ..")
sleep(2)
class func2(Thread):
def run(self):
for i in range(50):
print("2 ..")
sleep(2)
t1 = func1()
t2 = func2()
t1.start()
sleep(0.2)
t2.start()
t1.join()
t2.join()
#Here basically multiple threads are working simultaneously.
# Here Three threads are working-
# 1. main thread
# 2. t1
# 3. t2
'''