content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def check_your_guess(ans, your_guess, turns, history):
"""
The function checks whether the format of user's guess is correct
and calculates how many left chances (depends on the format).
:param ans: str, the answer
:param your_guess: str, the letter user guesses
:param turns: int, how many left ... | 5b43858b8ce2af7f9683118fc318bdfbb702ffe8 | 586,887 |
def get_objects(client, keys):
"""Retrieve objects from configured memcached under specified keys
:param client: memcache client object
:param keys: list of strings
:return: direct bytestream, no need to read from buffer. If error or timeout, return None.
"""
objects = client.get_multi(keys)
... | b4abd213578595ce63fc5e7ad141bf9754c25770 | 488,651 |
import warnings
def get_weight(target_easy_negative, easy_negative, hard_negative):
"""
Args:
target_easy_negative ([type]): [description]
easy_negative ([type]): [description]
hard_negative ([type]): [description]
Returns:
w_h, w_e: scaling factor for hard and easy and ne... | 56d8bcbcfc21145a164ca1882d245225e13cf5c7 | 44,647 |
import copy
def regularize(l):
"""
If necessary mix in a small prior for regularization.
"""
epsilon=1e-3
l=copy.copy(l)
for i in range(0,len(l)):
if l[i]==0:
l[i]=epsilon
return l | cde50c63fef8b22e800daeecda29998e62813850 | 631,913 |
def get_N_teachers(school_type, N_classes):
"""Return the number of teachers / class for different school types."""
teachers = {
'primary':N_classes + int(N_classes / 2),
'primary_dc':N_classes * 2,
'lower_secondary':int(N_classes * 2.5),
'lower_secondary_dc':N_classes * 3,
'upper_secondary':int(N_classes *... | 7e931a57554e5fa1b81d00864ed6458c17dfce6b | 350,741 |
from typing import List
def get_options(command: dict) -> List[str]:
"""Extract options from Click's information dictionary retrieved via `to_info_dict`."""
params = command["params"]
result = []
for param in params:
result.extend(filter(lambda x: "--" in x, param["opts"]))
return result | 6526e5b64a641e0e05fce4c02c356cb39a9621c1 | 356,704 |
def key_kicking_dgs_to_end(name):
""" Key function to help sort faculty names, putting "DGS"/"TBD" at end of list."""
return "ZZZZZ"+name if not (" " in name) else name | c4d5b4e4aa74ef1212d9d6aa41b9d7bbfada786d | 389,806 |
def user_in_group(user_entry, group_name):
"""Check if a user is in a group. Note this will return false for the special group "public", even
though all users are technically in this group."""
try:
return group_name in [g.name for g in user_entry.groups]
except AttributeError as UserNotSignedIn:... | 47ccbb2f991da8a3659a84882c0828610bd1c83c | 552,767 |
def DependencyNameFromFullString(full_string: str)->str:
"""
Returns the part without version, only dependency name
"""
return full_string.split()[0] | 33ff38473ee0b23d4cb305d1208e6ca459c0b503 | 136,195 |
def _is_connected(parent, child, dag):
"""
Whether two node are connected.
Args:
parent (BaseNode): Parent node.
child (BaseNode): Child node.
dag (DagGraph): Graph instance.
Returns:
bool, True or False.
"""
return parent.name in dag.precursor_table.get(child.n... | 2ebc17022e4f926b775bfc621f712b2808056dde | 343,692 |
def is_logs_synced(mst, slv):
"""Function: is_logs_synced
Description: Checks to see if the Master binary log file name and log
position match that the Slave's Relay log file name and log position.
Arguments:
(input) mst -> Master instance.
(input) slv -> Slave instance.
... | 9ee81bd9cfa66fb450bdd289c9437ffc9bf349bb | 125,969 |
def GetProjectUriPath(project):
"""Return the URI path of a GCP project."""
return '/'.join(['projects', project]) | 774c373be9ec63e593c20a03f2673f5e05f08b9c | 220,717 |
def exclude_bad(data, columns, values):
"""Exclude rows of data with poor quality control flags.
eg. data_new = exlcude_bad(data,
['Practical Salinity Corrected QC Flag '],
[0,4,9])
:arg data: the data set
:type data: pandas DataFrame
:a... | 22e1c73ea66e0da6d93b1899456d13f1046ca2c7 | 108,377 |
def has_c19_scope (scopes):
""" Check if the COVID-19 GLIDE number or HRP code is present """
for scope in scopes:
if scope.type == "1" and scope.vocabulary == "1-2" and scope.code.upper() == "EP-2020-000012-001":
return True
elif scope.type == "2" and scope.vocabulary == "2-1" and s... | 1d9c96d093450bd4ab0200eb190302b36eb593f7 | 685,311 |
import json
def loop_casts(casts: list) -> dict:
"""Loop all casts and remove duplicates by putting them into a dict using
the first timestamp as a key in timeseries list
:param casts: list of paths
:return: dict of casts as dict
"""
by_start_time = dict()
for now_c in casts:
with... | 057e64e1f4f76e337f34d644d0896bfc4967c778 | 214,213 |
def get_labels(data):
""" Returns the list of labels for the given issue or PR data.
"""
return [edge["node"]["name"] for edge in data["node"]["labels"]["edges"]] | c6a1f26f812cab3c8512d01b09948eef78445ae6 | 292,894 |
def dlr_list(client_session):
"""
This function returns all DLR found in NSX
:param client_session: An instance of an NsxClient Session
:return: returns a tuple, the first item is a list of tuples with item 0 containing the DLR Name as string
and item 1 containing the dlr id as string. The ... | a7cee3130bb5d178d3c254b998cb4ade1c7803fc | 627,208 |
def schedule_url(year, stype, week):
"""
Returns the NFL.com XML schedule URL. `year` should be an
integer, `stype` should be one of the strings `PRE`, `REG` or
`POST`, and `gsis_week` should be a value in the range
`[0, 17]`.
"""
xmlurl = 'http://www.nfl.com/ajax/scorestrip?'
if stype =... | 0d6c6a2721fcffa558a2b8db8c21d2ee2d2dc0d2 | 422,046 |
def _all_na_or_values(series, values):
"""
Test whether every element in the series is either missing or in values.
This is fiddly because isin() changes behavior if the series is totally NaN
(because of type issues)
Example: x = pd.DataFrame({'a': ['x', np.NaN], 'b': [np.NaN, np.NaN]})
x.... | f6c3f05a7dc2ad03047b1529cdcd00f6dd091899 | 42,168 |
def fmt_mate(mate_score):
"""Format a mate value as a proper string."""
if mate_score < 0: # mate in X for black
return "-M{:d}".format(abs(mate_score))
else: # mate in X for white
return "+M{:d}".format(abs(mate_score)) | 21b17fe934dd7f05b75743bc86b61a58dee45325 | 376,448 |
def tag_search(html_document):
"""
This function searches all the tags in the html document
:param html_document:
:return All the tags as a list:
"""
tags = [] # tag container
index = 0
while index < len(html_document): # traverse through all the document
tag = ''
if h... | 7fe9f33ef4b5cadb0f6a2555e4132948a2eab271 | 185,139 |
def surround_text(text, left='>>', right='<<', pad=2, preserve_whitespace=True):
"""
Surround ``text`` string with the characters from `left` and `right` - if color is not enabled this is
a good way to draw attention to a particular block of text.
:param text: the text to surround
:type text: str
... | 3dfbfda2b8ebb03d93d8e9bb3e5972ea38bc536a | 159,123 |
import typing
def get_paths(spec: dict) -> typing.List[str]:
"""This function extracts a list of paths from an OpenAPI specification.
:param spec: a dict with an OpenAPI specification
:return: a list of OpenAPI path strings (e.g.: /pets, /pets/{pet_id})
"""
return [str(k) for k in spec['paths'].k... | cee9381b068f812f4912053a1d7808b775967661 | 509,962 |
def remove_words(words_to_remove, list_of_strings):
"""
words_to_remove: list of words to remove
list_of_strings: list of string from which to remove words
>>> remove_words(['bye'], ['hello, bye', 'bye, hi'])
['hello, ', ', hi']
"""
for word in words_to_remove:
list_of_strings = [s.replace(word, ... | a4c8d9efd3e80908ec231be66b111ca5a27e372e | 327,765 |
import itertools
def _flatten_sentences(sentences):
"""
Flatten a list of sentences into a concatenated list of tokens.
Adapted from https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists.
>>> s1 = 'the gunman kill police'.split()
>>> s2 = 'police killed the gunma... | f6acab1f578a8dfa23b4de9225f4a0efee4705be | 483,357 |
def get_datatype_metranet(datatype):
"""
maps de config file radar data type name into the corresponding metranet
data type name and Py-ART field name
Parameters
----------
datatype : str
config file radar data type name
Returns
-------
metranet type : dict
diction... | bf48063305b9815d28c3037e5d499687215de09f | 242,982 |
def _val_to_byte_list(number, num_bytes, big_endian=True):
"""
Converts an integer into a big/little-endian multi-byte representation.
Similar to int.to_bytes() in the standard lib but returns a list of integers
between 0 and 255 (which allows for bitwise arithmetic) instead of a bytearray.
"""
... | e4788217bdc6cfabc57d4c6d2bf290c887eaf19a | 151,223 |
import torch
def get_ndc_rays(H, W, focal, near, rays_o, rays_d):
"""
Transform rays from world coordinate to NDC.
NDC: Space such that the canvas is a cube with sides [-1, 1] in each axis.
For detailed derivation, please see:
http://www.songho.ca/opengl/gl_projectionmatrix.html
https://github... | 6bba680569bbe2401b0c3462f28faaa2867240ad | 611,591 |
def nrlist(sequence):
"""Python 2.7 compatible list deduplication
"""
unique = []
[unique.append(item) for item in sequence if item not in unique]
return unique | 24af53cb426898c48cacc7772f582899dca9b4d1 | 347,425 |
def find_two_entry_product(numbers):
"""
Given the list of numbers, print the product of two that sum to 2020.
numbers (list): A list of integers.
Return (int): The product of two entries in numbers that sum to 2020.
Raises:
ValueError if no two entries in numbers sums to 2020.
>>> l... | abf225ec9f676ecb18d7663830f60232c92c25f7 | 320,270 |
import re
def total_balls(overs_str, str_ignore=['DNB', 'TDNB'], ignore_value=0):
"""
Calculate total balls bowled from overs formatting
Parameters
----------
overs_str: string
Overs bowled in traditional format overs.balls
str_ignore: list
Strings to ignore and return 0 - ind... | 084be59818abac177269fdce1a6911cd8b9d130a | 322,805 |
def class_as_descriptor(name):
"""Return the JVM descriptor for the class `name`"""
if not name.endswith(';'):
return 'L' + name + ';'
else:
return name | 128c344a73920d32dbbec65afd87cf4733920298 | 585,636 |
def week_day_on_first_auroran(dek_year: int) -> int:
"""Returns the Gregorian week day for the first Auroran of a given year
Args:
dek_year (int): Year.
Return:
int: The week day.
Example: 1 = Sunday; 2 = Monday; 3 = Tuesday ... 7 = Saturday.
"""
week_day = (
(1 + 5... | 3efb77275cf76fc8a03334ddce574b483e454d67 | 551,597 |
def count_digits(value):
"""
Count of digits of given number.
:param value: integer value (can also be negative)
:returns: count of digits of given number
>>> count_digits(0)
1
>>> count_digits(1024)
4
>>> count_digits(1234567890)
10
>>> count_digits(-1234567890)
10
... | 0ec0b8d6f7d4ea81b4f570370a0418f239e13b9b | 356,443 |
def get_ends(bed3):
"""Get the BED coordinates of the last nucleotide of each record."""
ends = bed3.copy()
ends['chrom_start'] = ends['chrom_end'] - 1
return ends.sort_values(by=['chrom', 'chrom_start']) | c67b4b1a220fa9c0ed71191d5cd7da29acf429f0 | 614,133 |
import yaml
def render_manifest(key_value_pairs):
"""Returns formatted cloud-init from dictionary k:v pairs"""
return "#cloud-config\n" + yaml.dump(
key_value_pairs, default_flow_style=False, default_style='\'') | 5a2a5f6adf9d10c93dc2761f759cfc45377ffd41 | 185,594 |
import torch
import math
def cal_GauProb(mu, sigma, x):
"""
Return the probability of "data" given MoG parameters "mu" and "sigma".
Arguments:
mu (BxGxC) - The means of the Gaussians.
sigma (BxGxC) - The standard deviation of the Gaussians.
x (BxC) - A batch of data ... | 3237d9dbc89968804dfe66722ef62f86f5000c4d | 656,970 |
import re
def parseLatLon(text):
"""Degrees/minutes/seconds notation (including cardinal direction) parsed
and converted to float value; returned in two-element tuple along with
single-characater cardinal direction.
"""
d, m, s, c = re.split('[^\w\.]', text)
value = float(d) + float(m) /... | 2b2e6698a4d0849b731c6b2e01127691731d7afb | 191,146 |
def _public_attrs(obj):
"""Return a copy of the public elements in ``vars(obj)``."""
return {
key: val for key, val in vars(obj).copy().items()
if not key.startswith('_')
} | a492f2fb9fc60f6551f376be468a0b88bbc490d0 | 141,073 |
import importlib
def fix_module_name(module, cls):
"""
Turns a.b._C.C into a.b.C if possible.
:param module: the module
:type module: str
:param cls: the class name
:type cls: str
:return: the (potentially) updated tuple of module and class name
"""
if module.split(".")[-1].starts... | 7d84b2fde58ed6b581f48088dfb30c9f08794508 | 538,851 |
def hydraulic_resistance_coefficient(Eg, Re, ke, d):
"""
:param Eg: Coefficient of hydraulic efficiency. If no data: Eg=0.95 for pipelines with scraper system; Eg=0.92 for
pipelines without scrapper system. Dimensionless
:param Re: Reynolds number. Dimensionless
:param ke: equivalent pipe roughness,... | d67c3feaf882b2e583491d30de5733ce11852324 | 116,099 |
def unNormalizeImage(image, mean=[0.485, 0.456, 0.406], STD=[0.229, 0.224, 0.225]):
"""
Unnormalizes a numpy array given mean and STD
:param image: Image to unormalize
:param mean: Mean
:param STD: Standard Deviation
:return: Unnormalize image
"""
for i in range(0, image.shape[0]):
... | 9fabf2a2114362cf751bb99b578f69940bfe594b | 426,772 |
import torch
def hsv2rgb(hsv):
"""
H, S and V input range = 0 ÷ 1.0
R, G and B output range = 0 ÷ 1.0
"""
eps = 1e-7
bb,cc,hh,ww = hsv.shape
H = hsv[:,0,:,:]
S = hsv[:,1,:,:]
V = hsv[:,2,:,:]
# var_h = torch.zeros(bb,hh,ww)
# var_s = torch.zeros(bb,hh,ww)
# var_v = t... | 4035d22ab6dcbf8fe62e6352dd15b0b5a1a60b5e | 502,932 |
import random
def pick_event(event_intervals):
"""
Returns a randomly selected index of an event from a list of intervals
proportional to the events' probabilities
:param event_intervals: list of event intervals
"""
i_event = 0
cumul_intervals = []
cumul_interval = 0.0
for interva... | 40856e66a272ce9a86b49b647bd85148cfd33703 | 663,989 |
def find_idx(words, idx):
"""
Looks for the named index in the list. Test for the index name surrounded
by quotes first, if it is not present then the error will return the index name without quotes
"""
try:
return words.index('"' + idx + '"')
except ValueError:
return words.inde... | 4c76fcd752de0545cea77def672d1555c071815f | 19,415 |
def find_in_list_of_lists(list_of_lists, value):
"""
Find value in list of lists and return first found index of list.
:param list_of_lists:
:param value:
:return:
"""
for i, lst in enumerate(list_of_lists):
if value in lst:
return i
return None | 99116e77e7bab189aaf4b04784d1145e56940d45 | 130,011 |
import re
def get_contents (fname):
"""
Return the contents of the given file.
Strip comments (lines starting with ;)
"""
if type(fname) == list:
contents = '\n'.join(fname)
else:
fp = open (fname, "r")
contents = fp.read()
fp.close()
return re.sub(r... | 1ec8cce0c8e4a719691b8c7f802eb3a9152e34cc | 633,318 |
def _int_bin_length(x):
"""Determine how many bits are needed to represent an integer."""
# Rely on the fact that Python's "bin" method prepends the string
# with "0b": https://docs.python.org/3/library/functions.html#bin
return len(bin(x)[2:]) | 84a5bbc6653931f3f158549ae99e194a4e6654b4 | 239,717 |
def render_name_to_key(name: str) -> str:
"""Convert the name of a render target with a valid dictionary key."""
return name.replace(".", "_") | e95135f659bc1700b102e51115e2be0955e7cb89 | 276,521 |
import csv
def read_csv(csvfile):
"""
Read CSV file and index by the unique id.
"""
index = {}
with open(csvfile, 'r') as data:
for row in csv.DictReader(data):
index[row['id']] = row
return index | f3da5f6075349a378fe49fe03b12005085b88e47 | 174,473 |
def _edge_func(G):
"""Returns the edges from G, handling keys for multigraphs as necessary.
"""
if G.is_multigraph():
def get_edges(nbunch=None):
return G.edges(nbunch, keys=True)
else:
def get_edges(nbunch=None):
return G.edges(nbunch)
return get_edges | ca488c5bde3b193ec308a99f66eb184bee6acd5c | 111,676 |
def descendants(term_id, ont_id_to_og, ont_id="17"):
"""
Get the descendant terms for a given input term.
Parameters
----------
term_id: The ontology term ID.
ont_id_to_og: The ontology graph ID map
ont_id: The ontology ID
Returns
---------
The term ID's of the descendant terms... | 2900edc89a50fe4dd27db34dcf68da3688e924e6 | 494,669 |
from pathlib import Path
import re
import json
def word_counter(json_flag, filename):
"""Counts unique words in a file, can output common or all words.
The occurrence of words (case is ignored) is counted. The output
is to stdout in a form similar to a histogram or frequency chart.
The output is the ... | 6954295d4bb6c3672b117db600d2cc5643be197b | 127,751 |
def join_col(col):
"""Converts an array of arrays into an array of strings, using ';' as the sep."""
joined_col = []
for item in col:
joined_col.append(";".join(map(str, item)))
return joined_col | f6386d99e69e3a8c04da2d7f97aa7fb34ac9044c | 25,386 |
def is_number(s):
"""
Check if a string s represents a number
Parameters
----------
s : `str`
String to check
Returns
-------
`bool`
``True`` if a string represents an integer or floating point number
"""
try:
int(s)
is_int = True
exc... | 192dc02300d4d614a12a9cb9282b8d35332c07e7 | 561,042 |
def formatAbn(abn):
"""Formats a string of numbers (no spaces) into an ABN."""
if len(abn)!=11:
return abn
return u'{0} {1} {2} {3}'.format(abn[0:2],abn[2:5],abn[5:8],abn[8:11]) | 2746c206ee5156fa7939ed11f04af1865824ef8c | 47,193 |
def table_exists(db_cur, table_name):
"""
Return a table name from a sqlite database to check if it exists.
Parameters:
db_cur(Cursor): A sqlite cursor connection.
table_name(str): Name of a table in the sqite database.
"""
query = "SELECT name FROM sqlite_master WHERE type='table' AND name... | 1d11f196d5175e28617a4c56e80a1a3878e6239f | 124,287 |
def drop(list_a: list, period: int):
"""Problem 16: Drop every N'th element from a list
Parameters
----------
list_a : list
The input list
period : int
The number of every N elements to drop
Returns
-------
list
A list without a number of dropped elements.
... | 10d8c6e1d968a4bd6890439a6200eabd75d5c3a9 | 197,487 |
def chunk(lst, n_chunks):
"""
https://stackoverflow.com/questions/2130016/
splitting-a-list-into-n-parts-of-approximately-equal-length
Parameters
----------
lst : list
n_chunks : int
Returns
-------
list
chunked list
"""
k, m = divmod(len(lst), n_chunks)
re... | 418fa1599676821bb897efd139d3c17c5facebb8 | 31,622 |
def _apriori_gen(frequent_sets):
"""
Generate candidate itemsets
:param frequent_sets: list of tuples, containing frequent itemsets [ORDERED]
>>> _apriori_gen([('A',), ('B',), ('C',)])
[('A', 'B'), ('A', 'C'), ('B', 'C')]
>>> _apriori_gen([('A', 'B'), ('A', 'C'), ('B', 'C')])
[('A', 'B', '... | 9a5465b9a7bc26f15506c221e3187bbcd4910205 | 140,513 |
def hamming_dist(a, b):
"""Compute Hamming distance between two strings.
"""
assert len(a) == len(b)
return sum(1 for i in range(len(a)) if a[i] != b[i]) | 97b8060030dc3dd542dba6ab1225fc26da6ff347 | 187,659 |
def normalize_From(node):
""" Return a list of strings of Python 'from' statements, one import on each
line.
"""
statements = []
children = node.getChildren()
module = '.'*node.level + node.modname
for name, asname in children[1]:
line = 'from %s import %s' % (module, name)
i... | 133405ceb331582aa023f78ac71e9c6fed8760f8 | 92,125 |
def extract_issues_html(html):
"""
Extracts the part of the HTML page, which contains the list of issues
Testing the relevant part avoids getting false positives/negatives
due to certain texts being present also in other parts of the page.
"""
return html.split('id="issues"')[1] | 56304effc096bb5007d7f3c04bc87860a602c10d | 598,578 |
def is_container(obj):
"""Check if `object` is a list or a tuple.
Args:
obj:
Returns:
True if it is a *container*, otherwise False
"""
return isinstance(obj, (list, tuple)) | 09db5b1d136b6db1969097d19f7d63d1750971ab | 70,805 |
import json
def _read(config_filename):
"""Read a comment-augmented json file from the given filename."""
with open(config_filename) as f:
lines = f.readlines()
content_lines = [l for l in lines if not l.lstrip().startswith('//')]
content = ''.join(content_lines)
return json.loads(content) | ccfb9b36b88c5e15d1224be75f6dce03e4e1dd78 | 490,480 |
def wrap(x, m, M):
"""Wraps ``x`` so m <= x <= M; but unlike ``bound()`` which
truncates, ``wrap()`` wraps x around the coordinate system defined by m,M.\n
For example, m = -180, M = 180 (degrees), x = 360 --> returns 0.
Args:
x: a scalar
m: minimum possible value in range
M: max... | eb86baba697a0890ff90e176fffa0e7cd904d0bd | 668,931 |
def get_trunc_minute_time(obstime):
"""Truncate obstime to nearest minute"""
return((int(obstime)/60) * 60) | 1a1a6ba47573442f0e98ca9aeaa8a5506e7ab081 | 15,942 |
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 |
def prune_wv(df, vocab, extra=["UUUNKKK"]):
"""Prune word vectors to vocabulary."""
items = set(vocab).union(set(extra))
return df.filter(items=items, axis='index') | 1e42a8426a5b931f9d611f7773d7d018c85ca507 | 685,907 |
import torch
def get_ranks(outputs):
"""
Returns the ranks according to the outputs (1 for highest grade). Deal with draws by assigning the best rank to the
first output encountered.
Args:
outputs: torch.Tensor, (batch_size, 1 ou 2) tensors outputs.
Returns:
torch.Tensor, ranks c... | 8e586938ce2addc91bdcb52b34e09be813bf211a | 415,157 |
def lr_update(
num_updates: int,
warmup_updates: int,
warmup_init_lr: float,
lr_step: float,
decay_factor: float,
) -> float:
"""InverseSquareRootSchedule.
https://github.com/pytorch/fairseq/blob/master/fairseq/optim/lr_scheduler/inverse_square_root_schedule.py#L32
Args:
num_up... | bcc5f1b26e26f1e683893095ad11870868d888a1 | 338,368 |
def input_volume(input_mass, input_conc):
"""
Computes the required amount of volume for a given mass and concentration.
Silently assumes that the units are:
- input_mass: ng (nanograms)
- input_conc: ng/µL (nanograms per microlitre)
"""
return input_mass / input_conc | f23799616c3583d03e2c47739a038e1a24182755 | 136,261 |
def calculate_time_from_stop(segment_df, dist_along_route, prev_record, next_record):
"""
Calculate the time from stop within the tuple (prev_record, next_record)
Algorithm:
if prev_record = next_record:
the bus is parking at the stop, return 0
Calcualte the distance within the tuple
Ca... | 3e441b76aff11db8850cd90e695b4d8edc7ea01a | 357,694 |
def SubstTemplate(contents, values):
"""
Returns the template with substituted values from the specified dictionary.
Keywords to be substituted are surrounded by '@': @KEYWORD@.
No attempt is made to avoid recursive substitution. The order
of evaluation is random based on the order of the keywords returne... | ff7fd400c9502af1a8e7a9e1dde81dd6d6d411ae | 425,062 |
def map_to_range(x: int, from_low: int, from_high: int, to_low: int, to_high: int) -> int:
"""
Re-map a number from one range to another.
A value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between.
Do not constrain values to within the range, be... | ab69a069c9544b8a2546f849f8544e81631a6870 | 46,890 |
def c_array(py_array, c_type):
"""Makes a C array from a python list or array and a C datatype
Arguments
----------
py_array: array-like data to convert
c_type: C datatype to which elements of py_array will be converted
Returns
-------
C array of chosen datatype
"""
if not ... | c015fdd6d308d3956f94a2c33493e280b8aad2a3 | 380,813 |
def split_fqdn(fqdn):
"""
Unpack fully qualified domain name parts.
"""
if not fqdn:
return [None] * 3
parts = fqdn.split(".")
return [None] * (3 - len(parts)) + parts[0:3] | 6615456641d09e8e1f2d4f38517204b3db1e1d7c | 691,045 |
import uuid
def get_uuid(data):
"""Compute a UUID for data.
:param data: byte array
"""
return str(uuid.uuid3(uuid.NAMESPACE_URL, data)) | f91e6e76c14736c1678bc000b7246ac6b518171f | 22,656 |
def scale_series(ds):
"""
Scale values in pandas data-series by minimum value in series
:params ds: pandas data-series
"""
return ds / ds.min() | 9ace3db3b869a59bd2113da50413d1ba73990ec9 | 240,282 |
def read_map_file(file_name):
"""
reads a map file generated by TI's ARM compiler. the function expects a file of a form similar to:
.
.
.
GLOBAL SYMBOLS: SORTED BY Symbol Address
address name
------- ----
00000000 __TI_static_base__
00000000 g_pfnVectors
00000200 __S... | 553fb838402220424a94335d3ad566c2a93a224f | 665,244 |
def tool_enabled(feature):
"""Generate the name of a feature to test whether it is enabled."""
return 'enable_' + str(feature) | a5707995ce3f726a16ecbb16b6edf3b2ffc2bebd | 357,616 |
import functools
def cached(f):
"""A simple caching decorator for instance functions not taking any arguments"""
@functools.wraps(f)
def g(self):
if not hasattr(self, "__cache"):
self.__cache = f(self)
return self.__cache
return g | 1ccf54d4523727b485f17dcbaf9ac0ea88b1a2cf | 162,722 |
def serializeEdge(edge):
"""Return the Edge as native Python datatypes, fit for json.
Edges only reference Knobs, so we have to store their Node id here
to be able to correctly associate it once reconstructed.
"""
return {
"source_nodeId": edge.source.node().uuid,
"source_name": edg... | 58662cdbfd1bc22e0dc4276e5240961dc0d5672a | 628,121 |
def is_palindrome(num):
"""Checks if a number is a palindrome. Does return True for single digit numbers"""
str_num = str(num)
for idx in range(len(str_num) // 2 + 1):
if not str_num[idx] == str_num[-idx - 1]:
return False
return True | eb85bf8e54cbae59d81783e1917b04ebb2239239 | 479,472 |
def contains(str1, str2):
"""Return true if str1 contains str2"""
try:
result = str1.find(str2)
except TypeError as e:
return False # Handle if str2 is None
except AttributeError as e:
return False # Handle if str1 is None
if result == -1:
return False
return Tr... | de7cf6136e29fb7f05d11ca9ce1765b1f467be83 | 228,770 |
import itertools
def _flip(items, ncol):
"""The items in `items` are listed in column order and displayed across
`ncol` columns. Re-order the list so that the items will be displayed
across rows rather than down columns."""
return list(itertools.chain(*[items[i::ncol] for i in range(ncol)])) | 266dc2d5758a2bcc3416ca67af4f9d2ee3422ab0 | 527,791 |
def escape_forward_slashes(s):
"""
Escape forward slashes for our custom escape scheme where
'/' escapes to '\f' and '\' escapes to '\b'. Note that
http://flask.pocoo.org/snippets/76/ recommends against
doing this, but the problem is that URL variable
boundaries can be ambiguous in some cases if... | 17ee9b799c6561d408c956e555ce286664fee94e | 317,278 |
import random
import string
def create_random_letters(digit):
"""
生成随机字母
:param digit: 大小写混合,参数为位数(长度)
:return:
"""
letters_list = [random.choice(string.ascii_letters) for i in range(digit)]
# string.ascii_letters=abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
random_letters = "... | 64fe5920bacc8cfd4b29ae5ae1f9f7551745644a | 603,255 |
def to_loxone_level(level):
"""Convert the given HASS light level (0-255) to Loxone (0.0-100.0)."""
return float((level * 100) / 255) | 9004c0eaa2ade4c664d30a0c79288d2f11a1362a | 656,894 |
import hashlib
def _hash(bs: bytes) -> bytes:
"""
Generic hash function for hashing keys.
"""
return hashlib.sha256(bs).digest() | a1059b37d579ee5d1700780fe9ed58f1a6637abc | 142,785 |
def is_palindrome(n):
"""
Fill in the blanks '_____' to check if a number
is a palindrome.
>>> is_palindrome(12321)
True
>>> is_palindrome(42)
False
>>> is_palindrome(2015)
False
>>> is_palindrome(55)
True
"""
x, y = n, 0
f = lambda: y * 10 + x % 10
while x >... | a20e69502c7609131e2fe27d1b92fe1563558c38 | 664,496 |
import re
def parse_remote_url(url):
"""Extract user, repo from URL."""
repo_urls = [
'https://gitlab.audeering.com/',
'http://gitlab.audeering.local/',
'http://gitlab2.audeering.local/',
'git@srv-app-01.audeering.local:',
r'^.*@gitlab.audeering.com/',
'https://... | 821a212fa43af01b956fbe226c388cb0b86ab71e | 558,655 |
def _extract_defines_from_option_list(lst):
"""Extracts preprocessor defines from a list of -D strings."""
defines = []
for item in lst:
if item.startswith("-D"):
defines.append(item[2:])
return defines | a8ecbe7a01052c313bc21f945edf4ff6e97ba35e | 515,439 |
def inaction(x):
"""Never intervene."""
return 0 | 8c719efc4210ce9b7a698b595f64e906f1482fe9 | 554,672 |
from typing import Tuple
def string_from_sentence(sentence: Tuple[Tuple]) -> str:
"""Get sentence as string from list of list representation
Args:
sentence (Tuple[Tuple]): Sentence in list of list representation
Returns:
str: Sentence as string
"""
return ''.join([edge[-1] for edge in sentence]) | c7abf8ff452835b6bbc5706e5e3718453dc5162c | 38,563 |
import re
def get_wiki_links(text: str) -> list:
"""
Get all wiki links from the given text and return a list of them.
Each list item is a dictionary with the following keys:
- wiki_link: the exact match
- link: the extracted link
- text: the possible extracted text
"""
wiki_links = []... | 133c94d532cde1ba95ecf310c2ec64923a3cc9b9 | 87,988 |
def to_sci_not(f):
"""Convert float `f` to a scientific notation string
(not including the `$`)
by using string formats `e` and `g`.
"""
s_e = f"{f:.4e}"
s_dec, s_pow_ = s_e.split("e")
s_dec = f"{float(s_dec):.4g}"
pow_ = int(s_pow_)
return f"{s_dec} \\times 10^{{ {pow_} }}" | d46b7ec7a7a87a2c444d1fee528b6bc44902f4b8 | 494,427 |
def index_data(word_index, data):
"""Function to convert a dataset to indexed instances based on a given word index.
:param word_index: given mapping of words to indices
:param data: list of text instances
:return: list of indexed instances
"""
data_vector = []
for instance in data:
... | f10dca89e859ba2a642de1fd4bd6c375174fd6e4 | 381,172 |
def best_time(time1, time2):
"""Return the best of two given times."""
time = min(time1, time2)
if time == 0:
return max(time1, time2) # if no time yet --> set the highest
return time | f9fc7274dfe34aeb6a480daf8aa68646748d5d19 | 501,837 |
def rename_labels_to_internal(x):
"""Shorten labels and convert them to lower-case."""
return x.replace("Experience", "exp").lower() | 9b39a5626768226492a200c0198115e432db0c78 | 519,395 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.