def schedule(self, env): """ Generates the context to execute in the following steps. """ for i, context in self.get_querypairs(env): if not self.is_valid(context): logger.error("Invalid arguments context:\n '{}''".format( pprint.format(context))) continue yield context
def add_github_context(context): github = {} for k in os.environ.keys(): if not k.startswith('GITHUB_'): continue github[k[7:].lower()] = os.environ[k] if not github: # FIXME: pull the data from the local git repository. github['sha'] = git_root_output = subprocess.check_output( ['git', 'rev-parse', 'HEAD']) assert not 'github' in context, pprint.format(context) context['github'] = github
import pprint message='It was a bright cold day in April,and thr clockks were striking thirteen.' count={} for char in message: count.setdefault(char,0) count[char]=count[char]+1 print(pprint.format(2))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import openpyxl import pprint #Install pip install openpyxl print('Opening workbook ...') wb = openpyxl.load_workbook('censuspopdata.xlsx') sheet = wb.get_sheet_by_name('Population by Census Tract') countyData = {} print('Reading rows...') for row in range(2, sheet.max_row + 1): state = sheet['B' + str(row)].value county = sheet['C' + str(row)].value pop = sheet['D' + str(row)].value # countyData[state].setdefault(county, {'tracts': 0, 'pop': 0}) countyData[state][county]['tracts'] += 1 countyData[state][county]['pop'] += int(pop) print('Writing results...') resultFile = open('census2019.py', 'w') resultFile.write('allData = ' + pprint.format(countyData)) resultFile.close() print('Done.')
#init dict count = {} for character in message: count.setdefault(character,0) #set default count for each letter passed to 0 count[character] = count[character] + 1 #pprint.pprint(count) print(pprint.pformat(count)) #same as line above prettyPrint() #prints a table w/ 2 cols and a row for each character ''' these functions are helpful especially when a dict contains nested lists or dicts to obtain prettified text as a STRING instead of printing it, call pprint.format() **********DATA STRUCTURES TO MODEL REAL-WORLD THINGS********* Algebraic Chess Notation --> spaces on chessboard are ID'ed by a # + letter coordinate - x-axis = a-h, y-axis = 1-8 Pieces are ID'd by letter (K = king, Q = queen, R = rook, N = knight) To describe a move, it uses the letter of the piece + coordinates of its dest. A pair of these moves describes a turn (white first) - 2. Nf3 Nc6 --> 2nd turn = W moved knight to f3, B moved knight to c6 There's more to algebraic notation than this, but we can now use it to unambiguously describe a chess game w/out needing a board
def make_panel(title, gs, row_ctr, panel_dict, data): panel_title = title ax = plt.subplot(gs[row_ctr, 0]) if type(panel_dict["x"]) != type(""): raise "X axis column name " + pprint.pformat( panel_dict["x"]) + " is not a string." if panel_dict["x"] not in data.columns.values: raise "Cannot find column " + panel_dict["x"] + " in dataset" # see whether there are labels to make a legend legend_labels = False if len(panel_dict["y"]) > 1 and "legend_labels" in panel_dict.keys(): # check whether the list of similar length as the list of # y variables if len(panel_dict["labels"]) != len(panel_dict["y"]): raise "Length of list of labels " + \ pprint.pformat(panel_dict["labels"]) + \ " differs from length of list of y axis variables " + \ ppprint.pformat(panel_dict["y"]) legend_labels = True if type(panel_dict["y"]) == type(""): panel_dict["y"] = [panel_dict["y"]] # multiple y values? if type(panel_dict["y"]) == type([]): # go through each of the y values for i, y_val in enumerate(panel_dict["y"]): ax.plot( data[panel_dict["x"]] ,data[y_val] ,label=panel_dict["legend_labels"][i] if \ legend_labels else y_val ) else: # just raise "Y variable container for " + title + " is not a string or list, " + \ pprint.format(panel_dict["y"]) # should we add a legend if "legend" in panel_dict.keys() and type(panel_dict["legend"]) == \ type(True) and panel_dict["legend"]: ax.legend() # only print tick labels in case it is explicitly # stated if "xticks" not in panel_dict.keys() or not panel_dict["xticks"]: ax.set_xticklabels(labels=[]) else: ax.set_xlabel(panel_dict["xlabel"]) if "xlim" in panel_dict.keys() and \ type(panel_dict["xlim"]) == type([]): ax.set_xlim(panel_dict["xlim"]) if "ylim" in panel_dict.keys() and \ type(panel_dict["ylim"]) == type([]): ax.set_ylim(panel_dict["ylim"]) ax.set_ylabel(panel_title)