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 selection_sort(nums): | |
| nums_length = len(nums) | |
| if nums_length < 2: | |
| return nums | |
| for k in range(nums_length): | |
| for i in range(k, nums_length): | |
| if i == k: | |
| smallest_idx, smallest = i, nums[i] | |
| else: |
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 insertion_sort(nums): | |
| nums_length = len(nums) | |
| if nums_length < 2: | |
| return nums | |
| for i in range(1, nums_length): | |
| x = i-1 | |
| while nums[i] < nums[x] and x >= 0: | |
| x -= 1 | |
| else: | |
| nums.insert(x+1, nums[i]) |
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
| from typing import List | |
| def quicksort(ints: List[int]): | |
| if len(ints) < 2 or len(set(ints)) == 1: | |
| return ints | |
| pivot = ints[0] | |
| ints_less_than_pivot = [x for x in ints[1:] if x <= pivot] | |
| ints_more_than_pivot = [x for x in ints[1:] if x > pivot] | |
| return quicksort(ints_less_than_pivot) + [pivot] + quicksort(ints_more_than_pivot) |
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
| import pdfkit | |
| # Fill this list with the html pages you want to be converted | |
| file_list = [] | |
| # Disable links since some point to local hard drive and dont work | |
| pdfkit.from_file(file_list, "generatedpdf.pdf", options={"disable-external-links": None, "load-error-handling": "ignore"}) |
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
| import unittest | |
| def flatten(arg_list, result_list): | |
| """ Flatten an array of arbitrarily nested arrays of | |
| integers into a flat array of integers. """ | |
| for x in arg_list: | |
| if isinstance(x, list): | |
| flatten(x, result_list) | |
| else: |
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
| from itertools import groupby | |
| from operator import itemgetter | |
| myvals = [('hello', 'arrival'), ('hi', 'arrival'), ('test', 'no'), ('voo', 'yes'), ('cool', 'arrival')] | |
| [(a,map(itemgetter(1), b)) | |
| for a,b in groupby( # 4. Group by key for which you have create list. | |
| sorted([(x, # 3. Sort the keys like arrival, yes, etc. | |
| reduce(lambda a,b: a+' '+b, map(itemgetter(0), y))) # 2. Concantenate the strs with same contiguous key. | |
| for x,y in groupby(myvals, key=lambda e: e[1])]), # 1. Group by key for which you have to concat 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
| import csv | |
| import json | |
| input_file = 'PROD_CUSTOMERS_GOOD.csv' | |
| output_file = 'wowcher_customer_creation_formatted.json' | |
| with open(input_file) as infile: | |
| infile.readline() | |
| with open(output_file, 'w') as outfile: |
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
| """ | |
| Search for a text in all repos for an organization. | |
| Currently via the web UI you can only search per repo. | |
| This will only return number of matches for the text and not | |
| the filenames (as of now). | |
| You need an OAuth Token for this to work. | |
| Run it as: |
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 mergesort(arr, n): | |
| if n == 1: return arr | |
| len_half = int(n/2) | |
| return merge(mergesort(arr[:len_half], len_half), | |
| mergesort(arr[len_half:], n - len_half), n) | |
| def merge(arr1, arr2, n): | |
| result = [] | |
| i,j = 0,0 | |
| for x in range(n): |
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
| import rlcompleter, readline | |
| readline.parse_and_bind('tab: complete') |
NewerOlder