Skip to content

Instantly share code, notes, and snippets.

def display(values):
"""
Display the values as a 2-D grid.
Input: The sudoku in dictionary form
Output: None
"""
print('')
rows = 'ABCDEFGHI'
cols = '123456789'
def cartesian_product(x,y):
'''
This function will take two iterables and returns
the cartesian product of them as a list
'''
return [a+b for a in x for b in y]
#@time_it
def set_method(st):
s = set()
repeat = set()
for letter in st:
if letter in s:
repeat.add(letter)
else:
s.add(letter)
return s-repeat
@zahash
zahash / non_repeating_character_dict_method.py
Last active January 3, 2019 12:20
function to find the non repeating character in a string
#@time_it
def dict_method(st):
'''
This function will return the non-repeating
characters in a string
Args:
st: the input string
Return:
def time_it(func):
def wrapper(*args, **kwargs):
start = time.time()
func(*args, **kwargs)
end = time.time()
return (end - start)*1000
return wrapper
#@time_it
def dict_method_v2(arr):
''' In this method we will remove some of the redundancies
of the dict_method
please note that this method takes a bit more time
because we are making more comparisions for the max_value
than before
Complexity : O(n)
#@time_it
def dict_method(arr):
''' In this method we will use dictionary to store the
count of each element and then search the dictionary
(or) hash map for the element with maximum count
this is one of the quickest methods
Complexity : O(n)
'''