Skip to content

Instantly share code, notes, and snippets.

View jmuzsik's full-sized avatar
⏲️

Jerry jmuzsik

⏲️
View GitHub Profile
def merge(lst1, lst2, lst3):
i1, i2, i3 = 0, 0, 0
n1, n2 = len(lst1), len(lst2)
while i1 < n1 and i2 < n2:
if lst1[i1] < lst2[i2]:
lst3[i3] = lst1[i1]
i1 = i1 + 1
else:
lst3[i3] = lst2[i2]
i2 = i2 + 1
def anagrams(s):
if s == "":
return [s]
else :
ans = []
for w in anagrams(s[1: ]):
for pos in range(len(w) + 1):
ans.append(w[: pos] + s[0] + w[pos: ])
return ans
def implement_higher_order_funcs(li, func_name, *args):
def append(the_list, item_to_append):
return the_list + [item_to_append]
def extend(list_one, list_two):
return list_one + list_two
def insert(the_list, idx, item):
return the_list[:idx] + [item] + the_list[idx:]
def dictionary_and_list(*args, li=[], dic={},**keywords):
if len(args) > 0:
for arg in args:
li.append(arg)
if len(keywords) > 0:
for keywd in keywords:
dic[keywd] = keywords[keywd]
return {'a_list': li, 'a_dictionary': dic}
dictionary_and_list('Ok, ', 'you ', 'are done, ')
liftoff = (x for x in range(17, 100, 17))
flat_list = []
for sublist in matrix:
for str in sublist:
flat_list.append(str)
transposed = []
for i in range(4):
transposed_row = []
for row in matrix:
transposed_row.append(row[i])
transposed.append(transposed_row)
matrix = [
['You ', 'it ', 'way. ', 'magically, '],
['must ', 'look ', 'Very ', 'important '],
['make ', 'this ', 'extremely, ', 'to do!']
]
def flatten_matrix(matrix):
return ''.join(
[
str for sublist in
def rev_args_key_concat_keywords_val(*args, **keywords):
dic = {}
rev_args_key = ""
concat_keywords_val = ""
args_len = len(args)
args = reversed(args)
for idx, arg in enumerate(args):
if arg is None:
continue
elif isinstance(arg, int):
def seperate_arbitrary_amount_words(num, dic):
word_sequence = ""
for i in range(num):
word_sequence += dic['a_list'][i]+dic['seperator']
return word_sequence
print(seperate_arbitrary_amount_words(3,
{'a_list': ['Trump', 'Genghis Khan', 'That noisy person', 'monkeys', 'coconuts'],
'seperator': ' is terrible! '}),'\n')