Skip to content

Instantly share code, notes, and snippets.

View Sukhrobjon's full-sized avatar

Sukhrobjon Golibboev Sukhrobjon

View GitHub Profile
@Sukhrobjon
Sukhrobjon / markov_chain_with_pseudocode.md
Last active April 8, 2019 20:03
Pseudocode for SPD-1.4

Read the existing text file Convert the text file into dictionary Start with blank sentence Choose the starting word from the dictionary randomly Put that word in the sentence at the beginning Set the first counter to zero Specify the number of words to create a sentence Repeat the iteration until counter is less the number of words in a sentence specified create an empty list set the second counter to zero

# list of number
number_arr = [1, 2, 3, 3, 4, 2]
print(number_arr) # [1, 2, 3, 3, 4, 2]
# we can wrap the same list of numbers in a set
number_set = set([1, 2, 3, 3, 4, 2])
# if we print it returns only distinct numbers
print(number_set) # {1, 2, 3, 4}
@Sukhrobjon
Sukhrobjon / dict_set.py
Last active May 8, 2019 21:41
This is sample code for medium article for CS-1.3 class at Make School
# declaring the dictionary with keys and values
dict_nums = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}
print(dict_nums) # {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}
# extracting the keys and putting in a list
list_keys = list(dict_nums.keys())
print(list_keys) # ['one', 'two', 'three', 'four', 'five']
def find_index(text, pattern):
"""
Return the starting index of the first occurrence of pattern in text,
or None if not found.
"""
window = len(pattern)
if len(pattern) == 0:
return 0
def find_index(text, pattern):
"""
Return the starting index of the first occurrence of pattern in text,
or None if not found.
"""
# if pattern is empty
if pattern == "":
return 0
#!python
from linkedlist import LinkedList
# Implement LinkedStack below, then change the assignment at the bottom
# to use this Stack implementation to verify it passes all tests
class LinkedStack(object):
def __init__(self, iterable=None):
# Longest Substring: https://leetcode.com/problems/longest-substring-without-repeating-characters/
def optimized_longest_substring(word):
seen = {}
# index is current index, starter is left pointer
# to keep track of the start of the sub string
index = starter = longest = 0
while index < len(word):
curr_char = word[index]
def find_fastest_route(self, from_vertex, to_vertex):
"""Finds for the shortest path from vertex a to b using
Dijkstra's algorithm:
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
Args:
from_vertex (str) : Starting point on the graph
to_vertex (str) : The final distanation
Returns:
shortest path (tuple): List of vertices in the path and len
Empty list if path does not exist
def infix_to_postfix(self, infix_input: list) -> list:
"""
Converts infix expression to postfix.
Args:
infix_input(list): infix expression user entered
"""
# precedence order and associativity helps to determine which
# expression is needs to be calculated first
precedence_order = {'+': 0, '-': 0, '*': 1, '/': 1, '^': 2}
def insert(self, expression: str):
"""
Insert the postfix expression into the tree using stack
"""
postfix_exp = self.infix_to_postfix(expression)
# if max size is 0, then it is infinite
stack = deque()
char = postfix_exp[0]
# create a node for the first element of the expression
node = BinaryTreeNode(char)