def mysort(): args = get_args() if args.custom: arr = args.custom else: arr = [randint(0, args.max) for i in range(0, args.size)] arr = sorted(arr, reverse=True) # make as hard as possible.. # make a copy as some of the sorting functions mutate the list. original_arr = list(arr) do_sort = { 'bubble': bubble, 'insertion': insertion, 'merge': merge, 'python': sorted, 'quick': quick, 'selection': selection, } arg_dict = vars(args) sort_type = [ key for key, value in arg_dict.items() if key in do_sort and value ][0] sorted_arr = do_sort[sort_type](arr) if args.verbose: print("\nOriginal array:\n") prtcols(original_arr, 42) print("\nSorted array:\n") prtcols(sorted_arr, 42) print("\nType: {} Sort".format(sort_type.capitalize()) + "\nLength: {:,}".format(len(original_arr)))
def main(): args = getargs() options = args.options chosen = chopt(options) os.system('cls') if os.name == 'nt' else os.system('clear') if chosen: print("\nChosen items:\n") prtcols(chosen, 6) print() else: print("\nNothing to see here.\n")
def main(): try: size = int(argv[1]) except ValueError: print("Invalid argument. Enter an integer.") exit(1) mylist = [randint(1, (size * 100)) for i in range(0, size)] print("Number of elements: {}".format(len(mylist))) number = count(mylist) prtcols(mylist) print("Number of elements: {}".format(number))
def menu(options, chosen): ''' Takes a list of options and selections as an argument and presents a checkbox menu with previously selected items still selected. ''' optstrs = [] os.system('cls') if os.name == 'nt' else os.system('clear') prtheader() for option in options: index = options.index(option) # print("{0:>1} {1:>2}) {2:}".format(chosen[index], index+1, option)) optstrs.append(chosen[index] + str(index + 1) + ") " + option) prtcols(optstrs, 10)
def main(): try: size = int(argv[1]) except ValueError: print("Invalid argument. Enter an integer.") exit(1) mylist = [randint(1, (size * 100)) for i in range(0, size)] print("Number of elements: {}".format(len(mylist))) mylist = sorted(mylist, reverse=True) largest = get_largest(mylist) prtcols(sorted(mylist)) print("Largest element: {}".format(largest))
def get_excludes(excludes, path): """ Takes a path as an argument and returns a list of child paths that the user has selected. """ os.system('cls') if os.name == 'nt' else os.system('clear') excludes = curses.wrapper(pick, path, relative=True, picked=excludes) if excludes: print("\nSelected excludes:\n") prtcols(sorted(excludes), 8) else: print("\nNo excludes selected.") if ask("Accept and continue? "): return excludes else: excludes = get_excludes(excludes, path) return excludes
def mkexcludes(automate_excludes, src): from textwrap import dedent """ Create valid rsync exclude arguments from a list of paths. """ excludes = [ '.*', '*.ost', '*.pst', '.DS_Store', '.localized', 'Applications', 'Library', 'Downloads', 'desktop.ini', ] err = None xargs = [] if not automate_excludes: while True: os.system('cls') if os.name == 'nt' else os.system('clear') print("\nDefault Excludes:\n") prtcols(excludes, 10) msg = """ Please select from the following options: (c)ontinue using default excludes listed above. (a)dd to excludes listed above using treepick. (d)elete all excludes and continue with no excludes. (r)emove all excludes and select different excludes. """ msg = dedent(msg).strip() print("\n{}\n".format(msg)) if err: print("{}\n".format(err)) ans = input("----> ") al = ans.lower() if re.match('^c(ontinue)?$', al): break elif re.match('^a(dd)?$', al): excludes = get_excludes(excludes, src) break elif re.match('^d(elete)?$', al): excludes = [] break elif re.match('^r(emove)?$', al): excludes = [] excludes = get_excludes(excludes, src) break elif re.match('^q(uit)?$', al): quit() else: err = ans + " is invalid." for x in excludes: if x.startswith(src): x = x.replace(src, '') xargs.append('--exclude="' + x + '"') return xargs