-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
He who conquers himself is the mightiest warrior | ||
Try not to become a man of success but rather become a man of value | ||
One man with courage makes a majority | ||
One secret of success in life is for a man to be ready for his opportunity when it comes | ||
The successful man will profit from his mistakes and try again in a different way | ||
A successful man is one who can lay a firm foundation with the bricks others have thrown at him | ||
Success usually comes to those who are too busy looking for it | ||
We cannot solve problems with the kind of thinking we employed when we came up with them | ||
Just one small positive thought in the morning can change your whole day | ||
You can get everything in life you want if you will just help enough other people get what they want |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pprint import pprint | ||
|
||
|
||
def count_chars(string): | ||
|
||
char_count = {} | ||
for char in string: | ||
char_count[char] = char_count.get(char, 0) + 1 | ||
return char_count | ||
|
||
|
||
pprint(count_chars('Happiness')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pprint import pprint | ||
|
||
source = 'yu' | ||
target = 'you' | ||
|
||
|
||
def levenshtein_distance(source, target): | ||
rows = len(source) + 1 | ||
cols = len(target) + 1 | ||
|
||
D = [[0] * cols for _ in range(rows)] | ||
|
||
for i in range(cols): | ||
D[0][i] = i | ||
|
||
for i in range(rows): | ||
D[i][0] = i | ||
|
||
for i in range(1, rows): | ||
for j in range(1, cols): | ||
cost = 0 if source[i-1] == target[j-1] else 1 | ||
|
||
D[i][j] = min(D[i-1][j] + 1, | ||
D[i][j-1] + 1, | ||
D[i-1][j-1] + cost) | ||
|
||
pprint(D) | ||
return D[rows - 1][cols - 1] | ||
|
||
|
||
levenshtein_distance(source, target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
num_list = [3, 4, 5, 1, -44, 5, 10, 12, 33, 1] | ||
k = 3 | ||
|
||
for i in range(len(num_list) - k + 1): | ||
sub_lst = num_list[i: i + k] | ||
|
||
row = num_list.copy() | ||
row[i] = f'[{num_list[i]}' | ||
row[i + k - 1] = f'{num_list[i + k - 1]}]' | ||
|
||
output = ', '.join([str(v) for v in row]) + f' => max {max(sub_lst)}' | ||
|
||
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pprint import pprint | ||
|
||
file_path = 'Module 1/Week 2/P1_data.txt' | ||
|
||
|
||
def word_count(file_path): | ||
with open(file_path, 'r') as f: | ||
text = f.read() | ||
words = text.split() | ||
word_counts = {} | ||
for word in words: | ||
word_counts[word] = word_counts.get(word, 0) + 1 | ||
return word_counts | ||
|
||
|
||
pprint(word_count(file_path)) |