Skip to content

Commit f394be5

Browse files
intial commit
intial commit
1 parent 129f4c6 commit f394be5

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Simple Generator for fibonacci number
2+
def sub(limit):
3+
#initializing first two fibonacci number
4+
a, b = 0, 1
5+
6+
#one by one yield next fibonacci number
7+
while a < limit:
8+
yield a
9+
a, b = b, a+b
10+
11+
x = sub(5)
12+
13+
#Using For in Loop
14+
print("\n For In Loop \n")
15+
for i in sub(5):
16+
print(i)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def simplegenerator():
2+
t = 1
3+
print ('First Result is :', t)
4+
yield t
5+
6+
t +=1
7+
print ('Second Result is :', t)
8+
yield t
9+
10+
t +=1
11+
print ('Third Result is :', t)
12+
yield t
13+
14+
x = simplegenerator()
15+
next(x)
16+
next(x)
17+
next(x)
18+
19+
print("Square From 1 to 10")
20+
21+
squarefun = (num ** 2 for num in range(10))
22+
for x in squarefun:
23+
print(x)
24+
25+
26+
string = 'PythoN'
27+
reverse = list(string[i] for i in range(len(string)-1, -1, -1))
28+
print(reverse)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Simple Generator Function
2+
def simpleGenerator():
3+
yield 1
4+
yield 2
5+
yield 3
6+
7+
x = simpleGenerator()
8+
9+
print(x.__next__());
10+
print(x.__next__());
11+
print(x.__next__());
12+

Control Flow/Switch Case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
1# -*- coding: utf-8 -*-
22
"""
33
Created on Mon Oct 28 16:37:20 2019
44
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class counter:
2+
def __init__(self, start, end):
3+
self.num = start
4+
self.end = end
5+
6+
def __iter__(self):
7+
return self
8+
9+
def __next__(slef):
10+
if self.num > self.end:
11+
raise StopIteration
12+
else:
13+
self.num += 1
14+
return self.num - 1
15+
16+
if __name__ = '__main__':
17+
a, b =2, 5
18+
19+
c1 = Counter(a, b)
20+
c2 = Counter(a, b)
21+
22+
print ("Print the range withot iter()")
23+
24+
for i in c1:
25+
print()

Control Flow/chain iteration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
python program for accnmulate() and chain()
3+
'''
4+
5+
import itertools
6+
7+
import operator
8+
9+
list_1 =[2, 5, 7, 9]
10+
11+
list_2 =[3, 6, 5, 3]
12+
13+
list_3 =[2, 5, 3, 2]
14+
15+
# using accumulate()
16+
print('The Sum After Each Iteration is : ',end = " ")
17+
print(list(itertools.accumulate(list_1)))
18+
19+
# using accumulate()
20+
#multipllication by iteration row wise
21+
print('The Product after each iteration is :' , end =' ')
22+
print(list(itertools.accumulate(list_1,operator.mul)))
23+
24+
#Print all Element of list
25+
print("All values in mentioned chain are :", end=' ')
26+
print(list(itertools.chain(list_1, list_2, list_3)))

0 commit comments

Comments
 (0)