Skip to content

Commit fd6a1aa

Browse files
committed
Itertools library learnt
1 parent 9560414 commit fd6a1aa

File tree

10 files changed

+379
-4
lines changed

10 files changed

+379
-4
lines changed

Cryptography/caeser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
data = "istiaq ahmed fahad"
2+
3+
encript = ""
4+
5+
for i in range(len(data)):
6+
x = (ord(data[i]) - 97 + 1) % 26
7+
x = chr(x+97)
8+
encript += x
9+
10+
print("Actual Text: ", data)
11+
print("Encripted Text: ", encript)
12+
13+
decript = ""
14+
15+
for i in range(len(encript)):
16+
x = (ord(encript[i])+97-1) % 26
17+
x = chr(x+97)
18+
decript += x
19+
20+
print("Decripted Text: ", decript)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import re
2+
3+
n = int(input())
4+
lines = []
5+
6+
for i in range(n):
7+
s = input()
8+
lines.append(s)
9+
10+
for line in lines:
11+
k = re.sub(r'( && )+', ' and ', line)
12+
k = re.sub(' ?\|\| ', ' or ', k)
13+
print(k)
14+

Miscellaneous Topics/lib_itertools.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from itertools import product
2+
3+
### Certain Products =====================================
4+
5+
# a = [[1,2,3],[4,5,6]]
6+
# print(list(product(*a)))
7+
# b = [1,2,3]
8+
# print(list(product(b, repeat = 2)))
9+
10+
# Task1: finding certesian products
11+
# a = input().split(" ")
12+
# b = input().split(" ")
13+
14+
# a = [int(i) for i in a]
15+
# b = [int(i) for i in b]
16+
17+
# ans = list(product(a,b))
18+
19+
# for i in ans:
20+
# print(i, end = " ")
21+
22+
### Permutations =====================================
23+
24+
# a = [1,2,3]
25+
# print(list(permutations(a)))
26+
# print(list(permutations(a, 2)))
27+
# print(permutations(a))
28+
# b = 'fahad'
29+
# print(list(permutations(b, 2)))
30+
31+
32+
# from itertools import permutations
33+
34+
# a = input().split(" ")
35+
36+
# a[0] = [i for i in a[0]]
37+
# a[1] = int(a[1])
38+
39+
# ans = list(permutations(a[0], a[1]))
40+
# ans = sorted(ans)
41+
42+
# for i in ans:
43+
# x = str.join("", i)
44+
# print(x)
45+
46+
### Combinations =====================================
47+
48+
from itertools import combinations, permutations
49+
50+
# a = [1,2,3,4]
51+
# print(list(combinations(a, 3)))
52+
# b = 'fahad'
53+
# print(list(combinations(b, 2)))
54+
# print(list(permutations(b, 2)))
55+
56+
a = input().split(" ")
57+
58+
a[0] = [i for i in a[0]]
59+
a[1] = int(a[1])
60+
61+
turn = a[1]
62+
for j in range(1, turn+1):
63+
64+
ans = list(combinations(a[0], j))
65+
ans = [sorted(i) for i in ans]
66+
ans = sorted(ans)
67+
68+
for i in ans:
69+
x = str.join("", i)
70+
print(x)

Python Fundamentals/lib_itertools.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from itertools import product
2+
3+
### Certain Products =====================================
4+
5+
# a = [[1,2,3],[4,5,6]]
6+
# print(list(product(*a)))
7+
# b = [1,2,3]
8+
# print(list(product(b, repeat = 2)))
9+
10+
# Task1: finding certesian products
11+
# a = input().split(" ")
12+
# b = input().split(" ")
13+
14+
# a = [int(i) for i in a]
15+
# b = [int(i) for i in b]
16+
17+
# ans = list(product(a,b))
18+
19+
# for i in ans:
20+
# print(i, end = " ")
21+
22+
### Permutations =====================================
23+
24+
# a = [1,2,3]
25+
# print(list(permutations(a)))
26+
# print(list(permutations(a, 2)))
27+
# print(permutations(a))
28+
# b = 'fahad'
29+
# print(list(permutations(b, 2)))
30+
31+
## Your task is to print all possible permutation of the string in lexicographic sorted order.
32+
33+
# from itertools import permutations
34+
35+
# a = input().split(" ")
36+
37+
# a[0] = [i for i in a[0]]
38+
# a[1] = int(a[1])
39+
40+
# ans = list(permutations(a[0], a[1]))
41+
# ans = sorted(ans)
42+
43+
# for i in ans:
44+
# x = str.join("", i)
45+
# print(x)
46+
47+
### Combinations =====================================
48+
49+
# from itertools import combinations
50+
51+
# a = [1,2,3,4]
52+
# print(list(combinations(a, 3)))
53+
# b = 'fahad'
54+
# print(list(combinations(b, 2)))
55+
# print(list(permutations(b, 2)))
56+
57+
## Your task is to print all possible size replacement combinations of the string in lexicographic sorted order.
58+
# a = input().split(" ")
59+
60+
# a[0] = [i for i in a[0]]
61+
# a[1] = int(a[1])
62+
63+
# turn = a[1]
64+
# for j in range(1, turn+1):
65+
66+
# ans = list(combinations(a[0], j))
67+
# ans = [sorted(i) for i in ans]
68+
# ans = sorted(ans)
69+
70+
# for i in ans:
71+
# x = str.join("", i)
72+
# print(x)
73+
74+
### Combinations with replacement =====================================
75+
76+
from itertools import combinations_with_replacement
77+
78+
# a = [1,2,7,3,4]
79+
# print(list(combinations_with_replacement(sorted(a), 3)))
80+
81+
## Your task is to print all possible size replacement combinations of the string in lexicographic sorted order.
82+
a = input().split(" ")
83+
84+
a[0] = [i for i in a[0]]
85+
a[1] = int(a[1])
86+
87+
ans = list(combinations_with_replacement(sorted(a[0]), a[1]))
88+
89+
for i in ans:
90+
x = str.join("", i)
91+
print(x)

Python Fundamentals/regex.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@
5858

5959
y = agentNamesRegex.sub(r'\1*****', 'Agent Alice told Agent Carol that Agent Eve knew Agent Bob was a double agent.')
6060
print(y)
61-

Python Socket Programming/.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python Socket Programming/Book Practice/EchoClient.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ def echo_client(port):
1111
sock.connect(server_address)
1212

1313
try:
14-
message = "Test message that will be echoed"
14+
15+
# data -----
16+
f = open("a.txt", "r")
17+
message = f.read()
18+
19+
# data -----
20+
# message = "Test message that will be echoed"
1521
print("[Client] Send:", message)
16-
sock.sendall(message.encode('utf-8')) # WRITING
22+
sock.sendall(message.encode('utf-8')) # *** WRITING ***
1723

1824
data_received = 0
1925
data_expected = len(message)
2026
content = ''
2127

2228
while data_received < data_expected:
23-
data = sock.recv(16) # READING
29+
data = sock.recv(16) # *** READING ***
2430
data_received += len(data)
2531
content += data.decode('utf-8')
2632
# print("[Client] Received:", data.decode('utf-8'))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world, istiaq ahmed fahad, University of California

0 commit comments

Comments
 (0)