This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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:] |
This file contains hidden or 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
| 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, ') |
This file contains hidden or 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
| liftoff = (x for x in range(17, 100, 17)) |
This file contains hidden or 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
| flat_list = [] | |
| for sublist in matrix: | |
| for str in sublist: | |
| flat_list.append(str) |
This file contains hidden or 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
| transposed = [] | |
| for i in range(4): | |
| transposed_row = [] | |
| for row in matrix: | |
| transposed_row.append(row[i]) | |
| transposed.append(transposed_row) |
This file contains hidden or 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
| matrix = [ | |
| ['You ', 'it ', 'way. ', 'magically, '], | |
| ['must ', 'look ', 'Very ', 'important '], | |
| ['make ', 'this ', 'extremely, ', 'to do!'] | |
| ] | |
| def flatten_matrix(matrix): | |
| return ''.join( | |
| [ | |
| str for sublist in |
This file contains hidden or 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
| 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): |
This file contains hidden or 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
| 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') |