content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def requirements(): """Returns the requirement list.""" with open('requirements.txt', 'r') as f: return [line.strip() for line in f.readlines()]
e40af4819eac602c4af4845e2f59233dc3fa8a62
699,176
def _query_pkey(query, args): """Append 'query' and 'args' into a string for use as a primary key to represent the query. No risk of SQL injection as memo_dict will simply store memo_dict['malicious_query'] = None. """ return query + '.' + str(args)
d524697af247879f6aca5fa3918d80199b6148d5
699,177
from typing import List from typing import Tuple def color_map_generate( colors: List[Tuple[int, int, int]], add_black_if_not_exist: bool = False ) -> List[Tuple[int, Tuple[int, int, int]]]: """ 컬러 리스트에서 [(id, 컬러)] 리스트를 생성합니다. 단, `(0, 0, 0)`이 있을 경우, 검은색의 id는 0으로 할당됩니다. `add_black_if_not_exist` 옵션...
38175b00d3f0bd5ba232cfcfd4b2e4bdb5ee7440
699,178
def collate_question(query, template, slot): """ Collate a question based on template and slot """ T1 = "select one to refine your search" T2 = "what (do you want | would you like) to know about (.+)?" T3 = "(which | what) (.+) do you mean?" T4 = "(what | which) (.+) are you looking for?" ...
1d615aa6b9b923b0f4c5dff0f01b9e04e45c41f5
699,179
import re def paragraph_newline(paragraphs): """Format newlines for paragraphing""" # Put new paragraphs here; will be joined on '' newlined_ps = [''] first_footnote = True line = re.compile('\(\d\d*\)') poet_line = re.compile('/\n') footnote_line = re.compile('\[\^\d\d*\]:') for i,...
d43ef0de1f95945a747d44957bb86128e1281c5c
699,180
from typing import Dict def alias(alias: str) -> Dict[str, str]: """Select a single alias.""" return {"alias": alias}
9321f00118658dc74fbc9704f1ea0e4a33e1f7aa
699,181
import subprocess def pdf(filename): """Generates a .pdf file. Use the pdf latex instance (must be installed) """ p = subprocess.Popen(['/usr/bin/pdflatex', filename +".tex" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) #bash command in python out, err = p.communicate() ...
7cd8809134bb75ac37caca79f560ca4c600e2348
699,182
def fix_hardmix(): """Fixture for a hard mixture""" return { "background": {"markov:rmin_500_rmax_1000_thresh_0.8_priceVarEst_1e9": 1}, "hft": {"noop": 1}, }
dee9b13b6b7f14ae334a6e1eda6c1fd2a362ba32
699,183
def max_digits(x): """ Return the maximum integer that has at most ``x`` digits: >>> max_digits(4) 9999 >>> max_digits(0) 0 """ return (10 ** x) - 1
3f0ffdfbbb3fdaec8e77889b3bfa14c9b9829b2e
699,184
def to_numpy(t): """ If t is a Tensor, convert it to a NumPy array; otherwise do nothing """ try: return t.numpy() except: return t
3ac3ef0efd9851959f602d42e7f38bdd7e5da21a
699,185
def get_name_from_choice(value, choice): """選択肢から値によって、表示名称を取得する :param value: 値 :param choice: 選択肢 :return: """ for k, v in choice: if k == value: return v return None
00055bc53aeba244a751f9dffe5c1fa2a7c71383
699,186
def var_series(get_var_series, n) -> list: """ :param get_var_series: func return random value :param n: number of elements :return: variation series """ l = [] for i in range(n): l.append(get_var_series()) l.sort() return l
95400d8f3368d7777ed9bf6d1fb42bc06aa3f17d
699,187
import argparse def get_parser(): """Get parser.""" parser = argparse.ArgumentParser(description="Parameters for H-UCRL.") parser.add_argument( "--agent", type=str, default="RHUCRL", choices=["RARL", "RAP", "MaxiMin", "BestResponse", "RHUCRL"], ) parser.add_argument...
9d815542ee18766da7ca6dc8cb298dc964b58a9a
699,188
def get_img_channel_num(img, img_channels): """获取图像的通道数""" img_shape = img.shape if img_shape[-1] not in img_channels: img_channels.append(img_shape[-1]) return img_channels
0627cffbb3e80fddccc47a4cc8b697a59cdda077
699,189
import pandas as pd def keep_common_genes(rna_df, sig_df): """ Given two dataframes, eliminate all genes that are not present in both dataframes. Both dataframes must be indexed with the same gene identifier Inputs: - rna_df: pandas df. Rows are genes (indexed by 'Hugo_Symbol') and columns are...
f934a351a8c5d8f158b33bb9233dbd62f9dd4c8a
699,190
def circulate(number, lower, upper): """ 数を範囲内で循環させる。 Params: number = 数。 lower = 数の下限。 upper = 数の上限。 Returns: 循環させた数。 """ if lower <= number <= upper: return number elif number < lower: return circulate(upper + lower + number + 1, lower, upper) e...
382b82768cc170b27b810c54d0ce753277d1a6f4
699,192
def auto_str(cls): """Auto generate string representation of the object. Args: cls: Class for which to generate the __str__ method. """ def __str__(self): return "%s(%s)" % ( type(self).__name__, ", ".join("%s=%s" % item for item in vars(self).items()), ...
71a95cfeecb00146898656a0150d97fc346ddad3
699,193
import argparse def get_train_input_args(): """ Command Line Arguments: 1. Data Folder as data_dir 2. Save Folder for checkpoints as --save_dir with default value 'checkpoints' 3. CNN Model Architecture as --arch with default value 'vgg16' 4. Learning rate as --learning_rate with defau...
1631d63783905f421ed2dc9c702673ff3866153a
699,194
import json def _jsonToDict(json_file): """Reads in a JSON file and converts it into a dictionary. Args: json_file (str): path to the input file. Returns: (dict) a dictionary containing the data from the input JSON file. """ with open(json_file, 'r') as fid: dout = json.loa...
6e4b5996d6aaf2982012c6c2f135d7876ee5b3ca
699,195
def _matches_app_id(app_id, pkg_info): """ :param app_id: the application id :type app_id: str :param pkg_info: the package description :type pkg_info: dict :returns: True if the app id is not defined or the package matches that app id; False otherwise :rtype: bool """ ...
4d6cd0d652a2751b7a378fd17d5ef7403cfdc075
699,196
def quad_pvinfo(tao, ele): """ Returns dict of PV information for use in a DataMap """ head = tao.ele_head(ele) attrs = tao.ele_gen_attribs(ele) device = head['alias'] d = {} d['bmad_name'] = ele d['pvname_rbv'] = device+':BACT' d['pvname'] = device+':BDES' d['bmad_f...
b35e04d78d419673afbc0711f9d454e01bc1dd5d
699,198
import os def _mkdir(dir_path): """Safely make directory.""" try: os.makedirs(dir_path) except OSError: pass return dir_path
f02ed083c90c25eb04c46e694da617b94eaacb29
699,199
import json def fix_hardprof_str(hardprof): """Fixture for a hard profile string""" return json.dumps(hardprof)
7cf08fceb561ebadcb44d6b13bcb7ad52198934d
699,200
def Imp(x, y): """Return True if X implies Y Performs a bitwise comparison of identically positioned bits and sets corresponding bit in the output. This amounts to the following truth table: X Y Output F F T T F F F T T ...
68ac0456879d0aedec58988de2528bd9c6141941
699,201
from typing import Callable from typing import Set from typing import Type def is_quorum(is_slice_contained: Callable[[Set[Type], Type], bool], nodes_subset: set): """ Check whether nodes_subset is a quorum in FBAS F (implicitly is_slice_contained method). """ return all([ is_slice_contained(n...
4a4af3af8ca5a3f969570ef3537ae75c17a8015c
699,202
import os def get_maps_dir(): """ Get the exploration/maps dir :return str: exploration/maps dir """ return os.path.join(os.path.dirname(os.path.dirname(__file__)), "maps")
d30410b4fe5e87f9183d18a7d5ee82d6f3cc0b7a
699,203
import os def _split_by_regions(regions, dirname, out_ext, in_key): """Split a BAM file data analysis into chromosomal regions. """ def _do_work(data): bam_file = data[in_key] if bam_file is None: return None, [] part_info = [] base_out = os.path.splitext(os.pat...
71007f0da5934aad0b3ed38ad96efd33707bdbe3
699,205
from re import match def extrakey(key): """Return True if key is not a boring standard FITS keyword. To make the data model more human readable, we don't overwhelm the output with required keywords which are required by the FITS standard anyway, or cases where the number of headers might change over ...
d4c36c3a5408d7056e55d5e67ebebe0b960e5b72
699,206
def P(N_c, N_cb, e_t, t, A, N_bb): """ Returns the points :math:`P_1`, :math:`P_2` and :math:`P_3`. Parameters ---------- N_c : numeric Surround chromatic induction factor :math:`N_{c}`. N_cb : numeric Chromatic induction factor :math:`N_{cb}`. e_t : numeric Eccentri...
82e444ca0e7563f061b69daedd82ff3fc771f190
699,208
import random import string def randomStringGenerator(length=13): """create random string ascii values""" return ''.join(random.choice(string.ascii_letters) for _ in range(length))
5f4406f67d953cc1198ae79ae049dbd6e9b678b4
699,209
import os import pickle def _load_static_data(module_path): """ load the data, raise the error if failed to load latlongrid.dat Parameters ---------- module_path : string mainpath of the LatLonGrid module Returns ------- latlondata : dict dictionary containing for each ...
e3ec215abb3bf7389c18583375d8a3c234af8cbf
699,211
import os def report_directory_path(): """Path to directory where monitor write report files to. This must point to the directory which is mounted to the monitor service container to read issued reports. """ base_directory = os.path.realpath( os.path.join(os.path.dirname(__file__), os.par...
555a901e0c665d753ec38d736264a7b37eb11a1f
699,212
def forensic(): """ brute force / comprendre le problème ... """ def is_strange(i): l = len(str(i)) if l == 1: return True if i % l != 0: return False return is_strange(i // l) def construction(i): s = str(i) l = len(s) if l...
02acb3a92aa2fc110ab356dc5786dac247c3c63f
699,213
import re def trim_http(url :str) -> str: """ Discard the "http://" or "https://" prefix from an url. Args: url: A str containing an URL. Returns: The str corresponding to the trimmed URL. """ return re.sub("https?://", "", url, flags = re.IGNORECASE)
472e71a646de94a1ad9b84f46fc576ed5eb5a889
699,214
def changeArc(G, i ,j): """ change statistic for Arc """ return 1
90b33be8ac87a67362b43185e688e8fdff218e64
699,215
def _jq_format(code): """ DEPRECATED - Use re.escape() instead, which performs the intended action. Use before throwing raw code such as 'div[tab="advanced"]' into jQuery. Selectors with quotes inside of quotes would otherwise break jQuery. If you just want to escape quotes, there's escape_quotes_if...
3c46caa1a02798a7b8539a92a6b68f29e3dcd63c
699,216
import codecs import os def fetch_data(cand, ref): """ Store each reference and candidate sentences as a list """ references = [] if '.txt' or '.en' in ref: reference_file = codecs.open(ref, 'r', 'utf-8') references.append(reference_file.readlines()) else: for root, dirs, files...
a72bce7f54ba93773425ae15081ea34b0be33f4e
699,218
import random def make_batch_pay_data(busi_type, client_tp): """ 批量代付标识,预付卡业务不填 :param busi_type: :return: """ if busi_type == "03": batch_pay = "" elif client_tp == "1": batch_pay = "2" else: batch_pay = random.choice(["1", "2"]) return batch_pay
28992bfe369f0befd3fc78022a2f1035174243c8
699,219
from pathlib import Path import os def clean(record: str) -> int: """ Clean up all cached data related to record. :param (str) record: User-supplied record file. :return: True if successfully cleaned; otherwise False. :rtype: int """ counter = 0 for file in Path(os.getcwd() + "/cache...
bd0e48d35ab5a6fdf0a82d5a9b1ed81a404c600b
699,220
def remove_recorders(osi): """Removes all recorders""" return osi.to_process('remove', ['recorders'])
c63f23a031a5c957fd8667fc5be87fbd96b26a1e
699,221
def removeCutsFromFootprint(footprint): """ Find all graphical items in the footprint, remove them and return them as a list """ edges = [] for edge in footprint.GraphicalItems(): if edge.GetLayerName() != "Edge.Cuts": continue footprint.Remove(edge) edges.app...
ddb047e00f98d73037abb5d9dc0a2e00de457f56
699,222
from typing import OrderedDict def to_options(split_single_char_options=True, **kwargs): """Transform keyword arguments into a list of cmdline options Imported from GitPython. Original copyright: Copyright (C) 2008, 2009 Michael Trier and contributors Original license: BSD 3-Clause "...
b5835d8d9f52fed1ba34799c319be06e9913a1e3
699,223
from typing import Match def gen_ruby_html(match: Match) -> str: """Convert matched ruby tex code into plain text for bbs usage \ruby{A}{B} -> <ruby><rb>A</rb><rp>(</rp><rt>B</rt><rp>)</rp></ruby> Also support | split ruby \ruby{椎名|真昼}{しいな|まひる} -> <ruby><rb>椎名</rb><rp>(</rp><rt>しいな</rt><rp>)</rp>...
bd603b67a61812152f7714f3a13f48cac41db277
699,224
import time def _generate_request_id(): """ 生成一个请求 id,暂时用 (时间戳 % 60 分钟) :return: """ return int(time.time() * 1000 % (60 * 60 * 1000))
b334265d41b68fc3455297bbc21065e7cb064920
699,225
def SkipIf(should_skip): """Decorator which allows skipping individual test cases.""" if should_skip: return lambda func: None return lambda func: func
135486c94640231328089115d61ba2d1eb87e46a
699,226
def norm(x, train_stats): """ Normalize the data. """ return (x - train_stats['mean']) / train_stats['std']
c7791c39b64a5041e537bb7554c0c4a7267d180c
699,227
import random import string def randomstring(size=20): """Create a random string. Args: None Returns: result """ # Return result = ''.join( random.SystemRandom().choice( string.ascii_uppercase + string.digits) for _ in range(size)) return result
64ecd935130f6308367d02a5d699ea05c906cbb2
699,228
def has_seven(k): """Returns True if at least one of the digits of k is a 7, False otherwise. >>> has_seven(3) False >>> has_seven(7) True >>> has_seven(2734) True >>> has_seven(2634) False >>> has_seven(734) True >>> has_seven(7777) True """ if k % 10 == 7: ...
8c0b7b02e36247b3685a6a0142ebd81dd63e220c
699,229
def get_subreport(binary_list, least_most_common_bit, bit_position): """Gets the report subset that has the least/most common bit within the specified bit position. Args: binary_list (): least_most_common_bit (): bit_position (): Returns: subreport (list): Subset that fulfil...
ca69762a416ead2dd3ba177150dc6a7ae6a6f494
699,231
def get_grid_size(grid): """Return grid edge size.""" if not grid: return 0 pos = grid.find('\n') if pos < 0: return 1 return pos
9ff60184bb0eed7e197d015d8b330dcf615b4008
699,233
def ts_code(code: str) -> str: """ 转换证券代码为 tushare 标准格式 :param code: :return: """ if len(code) != 9: raise Exception('无效的证券代码: 长度不符') stock_code = code.upper() if stock_code.endswith('.SZ') or stock_code.endswith('.SH'): return stock_code elif stock_code.startswith('S...
86f568553955ab66bcea7f86ecc341329f8931e3
699,234
def no_cache(func): """ Decorator made to modify http-response to make it no_cache """ def disable_caching(request_handler, *args, **kwargs): request_handler.set_header('Cache-Control', 'no-cache, no-store, must-revalidate') request_handler.set_header('Pragma', 'no-cache') reques...
f5f5b9c8e78a883395ad6cbf263c1c82b1aafdc9
699,235
def index() -> str: """ Static string home page """ return "Hello, Python!!!"
7bf6b684e8404d0b2d52bb7578e1f44e37bdf565
699,236
def get_unique_coords(df, lat_field, lon_field): """ Takes in a dataframe and extract unique fields for plotting. Uses dataframe group by to reduce the number of rows that need to be plotted, returns the lat and lon fields """ unique = df.groupby([lat_field, lon_field]).size().reset_index() ...
3914e59a9263e07a18833135b0d30a3e5b1d4ce6
699,237
import os def scanForFiles(folder_name, extensions=('.frm', '.bas', '.cls', '.vb')): """Return all suitable VB files in a folder and subfolders""" filenames = [] for subdir, dirs, files in os.walk(folder_name): for filename in files: filepath = os.path.join(subdir, filename) ...
685043454a105adeabe2768973d0a728f29fd6e4
699,238
def unhex(value): """Converts a string representation of a hexadecimal number to its equivalent integer value.""" return int(value, 16)
0a8c297a93f484c8a1143511ef8511521c887a78
699,239
def make_00a6(sucess): """キャラクター削除結果""" return ("\x00" if sucess else "\x9c")
2c89d1ba457a3d550742721ddfa9c6f6e7f391c7
699,240
def puzzles(): """ Import a list of Sudoku puzzles from text file and return it as a list Puzzles credit: http://norvig.com/top95.txt http://norvig.com/hardest.txt """ with open('sudoku_puzzles.txt') as file: data = file.readlines() #remove all end ...
e4f876c52b21756a9a97c6f1bc3a0cd2c00fca61
699,241
import threading import os def concurrency_safe_write(object_to_write, filename, write_func): """Writes an object into a unique file in a concurrency-safe way.""" thread_id = id(threading.current_thread()) temporary_filename = '{}.thread-{}-pid-{}'.format( filename, thread_id, os.getpid()) wri...
a2ef6dc6cb69523bc7fd487c2d1298a1c59d5323
699,242
import random def genRandomStructure(): """ Generates a random neural network structure. """ s = [] # Input layer has either 2 or three nodes. if random.uniform(0, 1) > 0.5: s.append(3) else: s.append(2) p = 1.0 while p > 0.5: # Add a new layer of random si...
efd1ea11e27cdea9222052ac7f12dbed89f5ac44
699,243
def filter_errors(seq, errors): """Helper for filter_keys. Return singleton list of error term if only errors are in sequence; else return all non-error items in sequence. Args seq: list of strings errors: dict representing error values Returns List of filtered items. """...
93f44cd933e48974c393da253b7f37057ea7de19
699,244
def _offset(x, y, xoffset=0, yoffset=0): """Return x + xoffset, y + yoffset.""" return x + xoffset, y + yoffset
a6c88b2ee3172e52f7a538d42247c0fdc16352f8
699,245
def filter_to_be_staged(position): """Position filter for Experiment.filter() to include only worms that still need to be stage-annotated fully.""" stages = [timepoint.annotations.get('stage') for timepoint in position] # NB: all(stages) below is True iff there is a non-None, non-empty-string # anno...
df771b0856c91c8663ad06cacf86bf3389df04c5
699,246
import sys def import_module(module_name): """ Improt module and return it. """ __import__(module_name) module = sys.modules[module_name] return module
5b74e1c4f0442b8bf37a3e4145d212698fd49c60
699,247
def leja_growth_rule(level): """ The number of samples in the 1D Leja quadrature rule of a given level. Most leja rules produce two point quadrature rules which have zero weight assigned to one point. Avoid this by skipping from one point rule to 3 point rule and then increment by 1. Parameters...
b93fe05a3bf9b8c016b92a00078dce8ef156a8c4
699,248
def nastran_replace_inline(big_string, old_string, new_string): """Find a string and replace it with another in one big string. In ``big_string`` (probably a line), find ``old_string`` and replace it with ``new_string``. Because a lot of Nastran is based on 8-character blocks, this will find the 8-char...
f9955d40a74fc57674e79dd6aeea3872ffc2c87d
699,249
import re def does_support_ssl(ip): """Check if IP supports SSL. Has aba sequence outside of the bracketed sections and corresponding bab sequence inside bracketed section. Examples: - aba[bab]xyz supports SSL (aba outside square brackets with corresponding bab within square brackets). ...
f46dda13d53717352fe27446d9fa3d0292d75c26
699,250
import six import json def meta_serialize(metadata): """ Serialize non-string metadata values before sending them to Nova. """ return dict((key, (value if isinstance(value, six.string_types) else json.dumps(value)) ...
a2ef8762c9d1b3d78dc401996392df0985c1c226
699,251
def keep_merge(walkers, keep_idx): """Merge a set of walkers using the state of one of them. Parameters ---------- walkers : list of objects implementing the Walker interface The walkers that will be merged together keep_idx : int The index of the walker in the walkers list that wil...
b029bd14cab4aec2cdf8edf27a9d63c2ffbbe61e
699,253
def get_md5_checksum_from_response(upload_response): """ Comparing the checksum of the local file with the returned checksum/Etag stored in the upload response. """ etag = upload_response.headers.get('Etag', '') upload_checksum = etag.replace('"', '') return upload_checksum
ffb9287066aed803f79a406224c54d9035e57fc3
699,254
def truncate_string(s, length=200, end="…"): """ A simplified version of Jinja2's truncate filter. """ if len(s) <= length: return s result = s[: length - len(end)].rsplit(" ", 1)[0] return result + end
4d97b31d0b9e6ee9eb0c14be88318271ebd1b3bb
699,255
import re import string def remove_more_punct(text): """ Parameters ---------- text : str String containing text we want to lowercase, remove puncuation, and tokenize. Returns ------- Tokenized list of words from passed string. """ punct = set(string.punctuation) tex...
992824627b35ef8a572d4e7e722cc2385cbd22c4
699,256
def is_nan(var) -> bool: """ Simple check if a variable is a numpy NaN based on the simple check where (nan is nan) gives True but (nan == nan) gives False """ return not var == var
0f91829f9b5ee3dfb22944d956066069b4a3f606
699,259
def load_instances(model, primary_keys): """Load model instances preserving order of keys in the list.""" instance_by_pk = model.objects.in_bulk(primary_keys) return [instance_by_pk[pk] for pk in primary_keys]
21f26f66047fc2b2871f77447035ba15fbf78fa7
699,260
def _merge_ns(base, override): """we can have several namespaces in properties and in call""" new_ns = {} for ns in base: new_ns[ns] = base[ns] for ns in override: new_ns[ns] = override[ns] return new_ns
935a5703b42c92104bff543da57183895cd11bf2
699,262
def GetHotlistRoleName(effective_ids, hotlist): """Determines the name of the role a member has for a given hotlist.""" if not effective_ids.isdisjoint(hotlist.owner_ids): return 'Owner' if not effective_ids.isdisjoint(hotlist.editor_ids): return 'Editor' if not effective_ids.isdisjoint(hotlist.follower...
0c03460d3e4190d4964a60a2753d31e1732b6e44
699,263
from unittest.mock import Mock from unittest.mock import patch def mock_gateway_fixture(gateway_id): """Mock a Tradfri gateway.""" def get_devices(): """Return mock devices.""" return gateway.mock_devices def get_groups(): """Return mock groups.""" return gateway.mock_gro...
6404cb18ce9dd0e97b33958958d7851ee5739bed
699,264
import re def create_contents(text, obsidian=False): """create a contents table from parsed headers obsidian flag indicates single file mode is being used (see file_converter) and markdown format over PDF""" if obsidian: contents = "## Contents" else: contents = "# Contents" head...
8011d0e2118497917e99a217fb7bfa025658cc35
699,265
import argparse def parse_args(): """Process input arguments""" parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('vcf', metavar='V', help="Input VCF file") parser.add_argument('--met...
b047d53e73f882f43bc4cde773273817c7420fef
699,266
from typing import Any def function_sig_key( name: str, arguments_matter: bool, skip_ignore_cache: bool, *args: Any, **kwargs: Any, ) -> int: """Return a unique int identifying a function's call signature If arguments_matter is True then the function signature depends ...
bfec647db5d819fb87cf3a227927acd5cd6dda10
699,267
def tenary_pass_through(*args): """Pass-through method for a list of argument values. Parameters ---------- args: list of scalar List of argument values. Returns ------- scalar """ return args
edbf7123bb2088b51aa27e72e0007c2f30f24d7b
699,268
import numpy def scores_vs_time(timeseries, numerator = 'fractionmatched'): """Process a timeseries as read by load_trajectory and return the fraction of each reference atom type found at each time. Parameters ---------- trajectory : dict Trajectory information as output by load_trajectory ...
17ec9d243425366ae92b15c0d4894379a9d8f2dc
699,269
import time def date_file_name(name): """Generate file name with date suffix.""" time_str = time.strftime("%Y%m%d-%H%M%S") return name + "_" + time_str
40e37e2a5dbc0208421f797bc2ae349414b05e4e
699,271
def compute_efficiency_gap(partition): """ Input is a gerrychain.Partition object with voteshare and population data. It is assumed that `add_population_data` and `add_voteshare_data` have been called on the given partition's GeoDataFrame. Returns the efficiency gap of the distri...
2982fe1b2f570c8eca27fade8915e9b117397cd1
699,272
import requests import json def updateData(url): """ Returns the symbol and the price of an asset. Parameters ----------- url: url used for information retrieval Returns ----------- tuple (symbol name, symbol price) """ res = requests.get(url); text = res...
b458dee9da7700f5c4f82a182724bba007c7a05f
699,273
def formatPublisher(publisher): """The publisher's name. """ return publisher
713cede34a67351d249439d83982331c60b26dcc
699,274
import os import sys def get_file_path(file): """ Get file path of file :param file: the filename """ return os.path.join(os.path.dirname(sys.argv[0]), "res", file)
015aa3a1b5d7c101c711bee23017cd926d6c9cdb
699,275
def has_phrase(message: str, phrases: list): """ returns true if the message contains one of the phrases e.g. phrase = [["hey", "world"], ["hello", "world"]] """ result = False for i in phrases: # if message contains it i = " ".join(i) if i in message: result = True return result
f56fcc261e21c538f1f23b811e14ae29d92f3038
699,276
from typing import Optional def substringBetween(s: str, left: str, right: str) -> Optional[str]: """Returns substring between two chars. Returns""" try: return (s.split(left))[1].split(right)[0] except IndexError: return None
5cda5bc57fe1f65053dffb047bef0b34e0a39a2b
699,277
def check_output(solution: str, output: str) -> bool: """Check if program's output is correct. Parameters ---------- solution Sample output taken from BOJ. output Output from program run. Returns ------- bool True if correct, False if wrong. """ solution...
66d35952d892842bd1b47329bfa7b77e0a878a51
699,278
from typing import Sequence def bit_array_to_int(bit_array: Sequence[int]) -> int: """ Converts a bit array into an integer where the right-most bit is least significant. :param bit_array: an array of bits with right-most bit considered least significant. :return: the integer corresponding to the bit...
d902a8e3db7b65ad348ef86cbfac371361aedd58
699,279
def clip_args(func, arg1, arg2, bounds=(0., 1.)): """ Clip the arguments to bounds Return the results of the function where the clipped arguments have been used. Arguments below the lower bound are set to the lower bound and the arguments above the upper bound are set to the upper bound. Param...
249b5fed30fd050da570ef5276f826c071457935
699,280
import math def euclidean_distance(p1, p2): """Calculate the euclidean distance of two 2D points. >>> euclidean_distance({'x': 0, 'y': 0}, {'x': 0, 'y': 3}) 3.0 >>> euclidean_distance({'x': 0, 'y': 0}, {'x': 0, 'y': -3}) 3.0 >>> euclidean_distance({'x': 0, 'y': 0}, {'x': 3, 'y': 4}) 5.0 ...
8cdc0e0534b2ed9272832fc0f977b9aa0e594c65
699,281
import re def read_raw_dictfile(filename, language): """Read from unformatted dictfile: eliminate extra spaces and parens, insert a tab. Return a list of word,pron pairs.""" S = [] with open(filename) as f: for line in f: words = re.split(r"\s+", line.rstrip()) S.appen...
a8c95c87551119a89bd2c686be35b3a3aba3f567
699,282
import zlib def zlib_handler(method): """ Prepare hash method and seed depending on CRC32/Adler32. :param method: "crc32" or "adler32". :type method: str """ hashfunc = zlib.crc32 if method == "crc32" else zlib.adler32 seed = 0 if method == "crc32" else 1 return hashfunc, seed
46e9d91e5ebe92f3b5b24f138ae693368128ce09
699,283
def hex_dump(string): """Dumps data as hexstrings""" return ' '.join(["%0.2X" % ord(x) for x in string])
7c0286c57387c5b8f6a79e2a9350eb54e480465a
699,284
def get_operands_dtype(operands): """ Return the data type name of the tensors. """ dtype = operands[0].dtype if not all(operand.dtype == dtype for operand in operands): dtypes = set(operand.dtype for operand in operands) raise ValueError(f"All tensors in the network must have the sa...
cda67513ea8ca9f7ea663d232a5358fad8f8597d
699,286
def get_j(xi, j=0): """ 得到小数定标标准化的j """ if xi / float(10 ^ j) <= 1: return j else: return get_j(xi, j+1)
975a74d70ceeba80debfadf171f6c32316cd7d7b
699,287
def get_shortest_path_waypoints_old(planner, origin, destination): """Return a list of waypoints along a shortest-path Uses A* planner to find the shortest path and returns a list of waypoints. Useful for trajectory planning and control or for drawing the waypoints. Args: planner: carla.macad_...
bb6cfdeb139c6c10cbd4fd8c4d0dc31083ecc2d6
699,288
def delete_container(client, resource_group_name, name, **kwargs): """Delete a container group. """ return client.delete(resource_group_name, name)
d69c3fbd89ce684942af4980ca9931908b12db6a
699,289