Skip to content

Commit af40118

Browse files
string_programs
1 parent da53e81 commit af40118

File tree

10 files changed

+138
-3
lines changed

10 files changed

+138
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
X = [[12, 7, 3],
2+
[4,5,6],
3+
[7,8,9]]
4+
5+
Y = [[5,8,1],
6+
[6,7,3],
7+
[4,5,9]]
8+
result = [[0,0,0],[0,0,0],[0,0,0]]
9+
# print(len(X))
10+
# print(len(X[0]))
11+
for i in range(len(X)):
12+
for j in range(len(X[0])):
13+
result[i][j] = X[i][j] + Y[i][j]
14+
15+
for i in result:
16+
print(i)
17+
18+
# comprehension_result = [[X[i][j]+Y[i][j] for j in range(len(X[0]))] for i in range(len(X))]
19+
# for i in comprehension_result:
20+
# print(i)
21+
# print(comprehension_result)
22+
23+
# transpose of a matrix
24+
traspose_result = [[0,0,0],[0,0,0],[0,0,0]]
25+
for i in range(len(result)):
26+
for j in range(len(X[0])):
27+
traspose_result [i][j] = result[j][i] # here element in ith column will be placed in jth column and element in jth element will be placed in ith column.
28+
29+
for i in traspose_result:
30+
print(i)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
X = [[12, 7, 3],
2+
[4, 5, 6],
3+
[7, 8, 9]]
4+
#j-0 1 2 3
5+
Y = [[5, 8, 1, 2], # k -0
6+
[6, 7, 3, 0], # k- 1
7+
[4, 5, 9, 1]] # k -2
8+
result = [[0,0,0,0],
9+
[0,0,0,0],
10+
[0,0,0,0]]
11+
12+
for i in range(len(X)):
13+
for j in range(len(Y[0])):
14+
for k in range(len(Y)):
15+
result[i][j] += X[i][k] * Y[k][j]
16+
for i in result:
17+
print(i)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def len_of_string(word):
2+
count = 0
3+
for _ in word: # here _ is throwaway variable...because we dont want it to be used to store any value
4+
count += 1
5+
return count # this function gives output of 7...like len() function of python.
6+
7+
8+
def check_palindrome(word):
9+
lo = 0
10+
hi = len_of_string(word)-1
11+
word = word.casefold() # will convert all letters to lower case
12+
print(word)
13+
while lo <= hi:
14+
if word[lo] != word[hi]:
15+
print(word[lo],"and", word[hi], "are not matching!")
16+
# print(word[hi])
17+
return False
18+
lo += 1
19+
hi -= 1
20+
21+
return True
22+
23+
print(check_palindrome(' aBcdCbA '))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
punctuation = ''' !()-[]{},:;'"<>./!@#$%^&*_-=|'''
2+
3+
my_string = "HEllo !@ , he said -----_________-------- and went|.............._____-----__-_-____-----__"
4+
5+
6+
no_puntuation= ""
7+
for char in my_string:
8+
if char not in punctuation:
9+
no_puntuation += char
10+
11+
print(no_puntuation.casefold())

Native-Datatypes/set_operations.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
E = {0, 2, 4, 6, 8}
2+
N = {1, 2, 3, 4, 5}
3+
4+
print("Union operation in python sets: ", E|N)
5+
6+
print("Intersection of E and N: ", E&N)
7+
8+
print("Difference of E and N: ", E-N) # will be considered for E...
9+
10+
print("Symmetric Difference of E and N: ", E^N) # jo dono sets me individually lie karta hai.
11+
12+
# also we have in-built functions in python for set operations
13+
print(E.union(N))
14+
print(E.intersection(N))
15+
print(E.difference(N))
16+
17+
print(E.symmetric_difference(N))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def sort_em_all(sentence):
2+
list_of_words = sentence.split()
3+
list_of_words.sort()
4+
5+
return list_of_words
6+
7+
sentence = 'Hello this Is an Example sentence With cAsed LettErS.'
8+
9+
result = sort_em_all(sentence)
10+
11+
for i in result:
12+
print(i, end=" ")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def count_vowel(sentence):
2+
3+
vowels = '''aeiou'''
4+
vowel_count = 0
5+
for char in sentence:
6+
if char in vowels:
7+
vowel_count += 1
8+
return vowel_count
9+
10+
sentence = 'Hello have you tried our tutorial section'
11+
12+
print(count_vowel(sentence))
13+
14+
def dict_vowel_count(sentence):
15+
vowels = 'aeiou'
16+
count_dict = {}.fromkeys(vowels, 0)
17+
18+
sentence = sentence.casefold()
19+
for char in sentence:
20+
if char in count_dict:
21+
count_dict[char] += 1
22+
print(count_dict)
23+
24+
dict_vowel_count("Hello have you tried our tutorial section")

functions/count_and_reverse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def reverse_num(num):
88
length += 1
99
return count, length
1010

11-
print(reverse_num(123676767676))
11+
print(reverse_num(12))

functions/dec_to_binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def dec_to_bin(num):
88
result_arr.append(digit)
99
binary += str(digit)
1010
num //= 2
11-
1211
result_arr.reverse()
12+
1313
return result_arr
1414

1515
a = dec_to_bin(4)

functions/shuffle_card.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import itertools, random
22
def shuffle_card():
33
deck = list(itertools.product(range(1, 14), ['Spade', "Heart", "Diamond", "Club"]))
4-
random.shuffle(deck)
4+
# random.shuffle(deck)
5+
print(deck)
56

67
for i in range(5):
78
print(deck[i][0], "of", deck[i][1]) # here deck[i][0] -- 5 denotes to number and deck[i][1] denotes to card name -- Club

0 commit comments

Comments
 (0)