content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def decomp(n):
""" Retorna a decomposição em fatores primos de um inteiro em forma de dicionário onde as chaves são
as bases e o valores os expoentes.
Ex:
>>> decomp(12)
{2: 2, 3: 1}
>>> decomp(72)
{2: 3, 3: 2}
:param n: number
:return: dictionary
"""
expoente = 0
base... | 999d8be04ffd197ebdd14c88b525eb8ca4379bb9 | 14,075 |
def sanitize_type_instance(index_name):
"""
collectd limit the character set in type_instance to ascii and forbids
the '/' character. This method does a lossy conversion to ascii and
replaces the reserved character with '_'
"""
ascii_index_name = index_name.encode('ascii', 'ignore')
# '/' is... | ece5008944a80ec45f20c3c8bf01575f162bb8e0 | 14,076 |
def validWorkspace(uri):
"""Function to check whether workspace is a geodatbase"""
if ".gdb" in str(uri) or ".sde" in str(uri):
return True
else:
return False | 073c1b992eee78dcb939b46215faed57e9bcf96c | 14,077 |
def get_run_zip_file_slug_sets(new_run, old_run_zip_files):
"""
:param old_run_zip_files: A list of run zip files.
:return: A set of provider slugs for each zip file.
"""
data_provider_task_records = new_run.data_provider_task_records.exclude(provider__isnull=True)
all_run_zip_file_slugs = [
... | 3dd2c472bcf3113f2544dcf7b4c13f956714429b | 14,078 |
import requests
def sendRequest(url, type="POST", params=None, headers=None):
"""
Send a request to a URL
### Input:
- `url` (str) | the url to send the request to
- `type` (str) | the type of request (GET or POST)
- `params` ... | 7f450b8eedf6405b237730b9f7d6da5277c41e7b | 14,080 |
def extract_milestones(github_issues: list) -> list:
"""Extracts milestone information from parsed issues."""
# Extract individual milestone fields, dedupe
deduped_milestone_names = {
x.get('milestone').get('name') for x in github_issues}
deduped_milestone_descriptions = {
x.get('milestone').get('d... | 236f2f55eeff9de9e149fcb920b642684f3ee1ab | 14,081 |
def format_number(value: float) -> str:
"""
Format a number into a string, where “.0” is removed if number does not have a decimal part.
:param value: The number to format.
"""
return str(int(value) if value % 1 == 0 else value) | 7f34c689a64753c97c664dadf61d57bdf837c8a6 | 14,082 |
def get_span_row_count(span):
"""
Gets the number of rows included in a span
Parameters
----------
span : list of lists of int
The [row, column] pairs that make up the span
Returns
-------
rows : int
The number of rows included in the span
Example
-------
C... | e226e0f78bd6711a7ddbe9c749ed43d1d2bc476c | 14,083 |
def parse_score_qa(output, metric, digits=4):
"""Function for parsing the output from `pyserini.eval.evaluate_dpr_retrieval`. Currently, the implementation is
the same as `parse_score_msmacro`, but we're keeping separate in case they diverge in the future."""
for line in output.split('\n'):
if me... | dbb2179fc1706618cc5a4ccfd88818d32086680b | 14,084 |
def get_logbook_by_name(logbook_name, conn):
"""
Get a logbook by name from a persistence backend connection
:param str logbook_name: The name of the logbook to get
:param obj conn: A persistence backend connection
:return obj logbook: The logbook with the specified name
"""
return next(
... | 7ed83cfca3d7f0313046b39032c2b906c4bff410 | 14,085 |
def is_inside_relative_range(value, ref_value, pct):
"""
Parameters
----------
value : numeric
ref_value : numeric
pct : numeric
pct should be smaller than 1.
Returns
-------
boolean
"""
if ref_value * (1 - pct) <= value <= ref_value * (1 + pct):
return True... | 9e60eda7b3ba979c9dc33be890d46394aa954436 | 14,087 |
from typing import List
def get_label_list(labels: List[List[int]]) -> List[int]:
"""Gets a sorted list of all the unique labels from `labels`.
Args:
labels: A list of lists, each corresponding to the label-sequence of a text.
Returns:
All the unique labels the ever appear in `labels`, g... | be795ff63c1eaccd221289708551a8ddd02b2cc5 | 14,088 |
def format_message(date_str, node, msg):
"""Format log message"""
message = f"{date_str}: {node.site_name}: {node.location or node.model} ({node.serial}) {msg}"
return message | 53dc7e2716f935a083c36e40ad4887cfe23c0aad | 14,089 |
def _deep_value(*args, **kwargs):
""" Drills down into tree using the keys
"""
node, keys = args[0], args[1:]
for key in keys:
node = node.get(key, {})
default = kwargs.get('default', {})
if node in ({}, [], None):
node = default
return node | fc821b5fe0758b582388c91be4139737970704b3 | 14,090 |
import os
def abspath(current_path, relative_path):
"""Build an absolute path from relative path"""
parent = os.path.abspath(os.path.dirname(current_path))
return os.path.join(parent, relative_path) | 19ec82d8629112bd2deb7c5bb80106426115f02a | 14,091 |
import tempfile
def create_tmpdir():
"""Create temporary directory where all intermediate files will be placed."""
return tempfile.mkdtemp(prefix='xl-') | 7cac5eb979b3d7150084daf68749b30a3986e52b | 14,093 |
import re
def get_aws_local_file(aws_creds_file):
"""
Converting aws config and credentials files into dictionaries
:param aws_creds_file: string
:return: dictionary
"""
aws_config = {}
current_profile = ''
input_file = open(aws_creds_file, 'r')
for line in input_file.readlines():
... | 3c0b323f8dc61f17953d72f9e8adb74ac3e0e828 | 14,094 |
def _bowtie_args_from_config(data):
"""Configurable high level options for bowtie.
"""
config = data['config']
qual_format = config["algorithm"].get("quality_format", "")
if qual_format.lower() == "illumina":
qual_flags = ["--phred64-quals"]
else:
qual_flags = []
multi_mapper... | 57e86765444657812d0bebc9b1a3c3dcb234d300 | 14,095 |
def split_unk(str_, vocab):
"""
将所有不在词表中的符号切分开,尽量保留在词表中的符号
"""
rstring = ""
for c in str_:
if c in vocab.keys():
rstring += c
else:
rstring += " " + c + " "
str_ = rstring
return str_ | c54da92f9e69f32949bba538242ea91cfdb197f9 | 14,096 |
def _world2fig(ff, x, y):
"""
Helper function to convert world to figure coordinates.
Parameters
----------
ff : `~aplpy.FITSFigure`
`~aplpy.FITSFigure` instance.
x : ndarray
Array of x coordinates.
y : ndarray
Array of y coordinates.
Returns
-------
coo... | 99df767d948bc1c0807b676e2178de1478a1ac71 | 14,098 |
def is_palindrome(number):
""" Returns True if `number` is a palindrome, False otherwise.
"""
num_str = str(number)
num_comparisons = len(num_str) // 2
for idx in range(num_comparisons):
if num_str[idx] != num_str[-1-idx]:
return False
return True | 391aec57bba8366d7e7ef2c8187fda377f5a786d | 14,099 |
from typing import Iterable
def flatten_list(li: Iterable):
"""Flattens a list of lists."""
if isinstance(li, Iterable):
return [a for i in li for a in flatten_list(i)]
else:
return [li] | 306536fdadf231b0a0f752bb63d7e01317819674 | 14,100 |
def improve_ensemble(energy, positions, ensemble, ensemble_energies, unchanged_iterations):
"""
Given an energy and positions for a single pose, as well as the same data for a reference ensemble, this function "improves" the quality of the ensemble by identifying poses with the lowest potential energy.
... | ac1dcf2ec104a886b61e2abe4b4e090724d47ce7 | 14,101 |
def get_static_welcome_message():
"""
Get the static welcome page.
"""
return \
"""
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the browser
shows you when you enter a search word. The search word was <b>green</b>.</li>
<li>The search result shows for different par... | f630c67ab66069baf8b82b5b4c5fe111b9191a73 | 14,102 |
def platform_name(project, platform):
""""Get the untrusted platform name."""
return project.upper() + '_' + platform.upper() | 3f63ab210ef040114a536cac40efbad168631273 | 14,103 |
import numpy
def lat2g0(lat):
"""Calculate surface gravitational acceleration for latitude
This function is stolen from atmlab:
https://www.sat.ltu.se/trac/rt/browser/atmlab/trunk/geophysics/pt2z.m
From the original description:
Expression below taken from Wikipedia page "Gravity of Earth", tha... | 7c907a8016b6a579dd0a16a1662bf02358778d16 | 14,104 |
def tpearson(x, y, axis=0):
"""Tensor-based pearson correlation."""
n = x.shape[axis]
xc = x - x.mean(axis=axis, keepdims=True)
yc = y - y.mean(axis=axis, keepdims=True)
xystd = x.std(axis=axis) * y.std(axis=axis)
cov = (xc * yc).sum(axis=axis) / n
corr = cov / xystd
return corr | 37da10d2e21f04296a2cc0b3f8b239e0fcba8957 | 14,105 |
import re
def remove_unwanted_chars(x: str, *chars: str, to_replace: str = "") -> str:
"""Remove unwanted characters from a string."""
return re.sub(f"[{''.join(chars)}]", to_replace, x) | 4a1e25b1ad12f47f835d4f6cdbac4a6e08413077 | 14,106 |
def write_the_species_tree(annotated_species_tree, output_file):
"""
this function writes the species tree to file
args:
annotated_species_tree : a string of annotated species tree in .newick format
output_file : a file name to write to
output:
a file containing the annotated sp... | 7db9d5fc10cd27b1e7a5e51427e7de6991a1157a | 14,107 |
import functools
def compose(*functions):
"""
A functional helper for dealing with function compositions. It ignores any None functions, and if all are None,
it returns None.
Parameters
----------
*functions
function arguments to compose
Returns
-------
function or None
... | 8a18b1e0beef43c0cfac4439fa158675a486b560 | 14,108 |
def pretty_print_list(lst, name = 'features', repr_format=True):
""" Pretty print a list to be readable.
"""
if not lst or len(lst) < 8:
if repr_format:
return lst.__repr__()
else:
return ', '.join(map(str, lst))
else:
topk = ', '.join(map(str, lst[:3]))
... | d199261e6b9fd226256a151601d0bd86e7458fe1 | 14,109 |
def factorial(n):
"""
:type n: int
:rtype: int
"""
f = n
for i in range(n - 1, 0, -1):
f = f * i
return f | 17d6e211911417507e5887232f181bf774396c73 | 14,110 |
def _generate_fake_input_arg_componentsdk(arg_spec):
"""Generate a fake argument value for inputs of module spec
Args:
arg_spec (dict) : argument specification from yaml module spec
Returns:
object: sample fake value
Raises:
NotImplementedError: if arg type is not implemented
... | 62d92059ff6df74f4f08e6c2d09186f48058b617 | 14,112 |
def docker_compose_project_name():
"""Set a consistent project name to enable optional reuse of containers."""
return "pytest-python-gitlab" | 0c8ed2e63692fec969c042b4e2e8094459045c5b | 14,116 |
def _partition(entity, sep):
"""Python2.4 doesn't have a partition method so we provide
our own that mimics str.partition from later releases.
Split the string at the first occurrence of sep, and return a
3-tuple containing the part before the separator, the separator
itself, and the part after the... | 0172ce09bd0451eb538122bd9566a3e70d0dcc15 | 14,117 |
def get_phe_title(db, phename):
"""
Search bar
SciDBnew:
res = str(list(phef[phef['description'] == "asthma_diagnosed_by_doctor"]['title'])[0])
"""
phef = db.get_phenotype_fields(association_set=str(db.list_association_sets()['name'][0]))
if phef.empty:
return None
else:
... | 93ef978e9b79760d0226cc0fd00d827f7b3872ff | 14,118 |
def compatibility_g_m(gen_1, gen_2, name_1, name_2):
"""Check compatibility."""
print("Checking compatibility of {} with {}.".format(name_1, name_2))
r_code = 0
for seq in gen_1:
if seq not in gen_2:
print("FAIL\t{} sequence not found in {}.".format(seq, name_2))
r_code =... | 0ce34eb6ebe97bca179425939c95a2a6a19f6e6a | 14,119 |
import sys
import subprocess
def _GetGitRevision(in_directory):
"""Returns the git hash tag for the given directory.
Args:
in_directory: The directory where git is to be run.
Returns:
The git SHA1 hash string.
"""
git_exe = 'git.bat' if sys.platform.startswith('win') else 'git'
p = subprocess.Po... | 4ee7abe93c3d63bec84e478725d7ca086599d74b | 14,120 |
import socket
def getaddrinfo(host, port=None, family=0, socktype=0, proto=0, flags=0):
"""return (family, socktype, proto, canonname, sockaddr)
>>> socket.getaddrinfo("www.python.org", 80, 0, 0, socket.SOL_TCP)
[(2, 1, 6, '', ('82.94.164.162', 80)),
(10, 1, 6, '', ('2001:888:2000:d::a2', 80... | 5fde1bc04887e002199e119b24cde08227d14c0b | 14,121 |
def coref_cleaning(t, new_coref_np, current_coref):
"""Assign the correct coreference tag according to
Args: t (token), new_coref_np (Boolean), current_coref (int)
Return: new_coref_np (Boolean), current_coref (int)
"""
if t.coref.startswith('(') and t.coref.endswith(')')... | 9e2d1db3316c6ddd2c09050b64838cc92d5dd651 | 14,123 |
def get_default_tokenizer():
"""Only support split tokenizer
"""
def _split_tokenizer(x, delimiter=None):
if delimiter == "":
return list(x)
return x.split(delimiter)
return _split_tokenizer | 91cc23378d230d9cb47fbe0c47cf7a33cbce5265 | 14,124 |
import json
def load_dict_from_json(filename: str) -> dict:
"""
Load the given file as a python `dict`
Parameters
----------
filename: `str` an absolute path to the json file to be loaded.
Returns
-------
`dict` The loaded json file as a python dictionary.
"""
with open(filen... | 1d55e5dbcf33e7f1d21063be7b722a5ed5bc6bb3 | 14,125 |
def collect_not_null_kwargs(**kwargs) -> dict:
"""
Collect not null key value pair from keyword arguments.
.. versionadded:: 1.0.1
"""
return {
k: v
for k, v in kwargs.items()
if v is not None
} | 84e3438b5a4f0a48a4b558cc50b65a21e5883af9 | 14,127 |
def get_n_neighborhood_start_stop_indices_3D(volume_shape, point, n):
"""
Compute the start and stop indices along the 3 dimensions for the n-neighborhood of the point within the 3D volume.
Note that this returns an index range where the end is *non-inclusive*! So for a point at x,y,z with 0-neighborhood (... | 6eb1c6f0b4ff537b3d0eb1b647b019a2d61480b7 | 14,128 |
from typing import Dict
from typing import Any
def add_to_dict_with_swapped_keys(old_dict: Dict[Any, Dict],
new_dict: Dict[Any, Dict]) -> Dict[Any, Dict]:
"""
Swap the keys of two nested dictionaries in a new dictionary.
{'Key1': {'Key2': 42}} -> {'Key2': {'Key1': 42}}
... | 2b4d0a0d8bd2734d8c0bc7abde1fa659454f1464 | 14,129 |
import os
def splitpath(full_path):
"""
Splits a path into all possible pieces (vs. just head/tail).
"""
head, tail = os.path.split(full_path)
result = [tail]
while len(head) > 0:
[head, tail] = os.path.split(head)
result.append(tail)
result = [x for x in result if len(x)]
return result[::-... | 427a9de5772459504026d235e5e9ff59259a5c80 | 14,130 |
import typing
import functools
def build_simple_validator(func: typing.Callable, *args, **kwargs) -> typing.Callable[[typing.Any], typing.Any]:
"""Build a ready-to-use simple validator out of a function.
Args:
- func: callable, the function to be called to validate an input
- args: list, args... | cc8227cce228579e51aa05ceb25d9020d51eb199 | 14,131 |
import torch
def quat_conjugate(a: torch.Tensor) -> torch.Tensor:
"""Computes the conjugate of a quaternion.
Args:
a: quaternion to compute conjugate of, shape (N, 4)
Returns:
Conjugated `a`, shape (N, 4)
"""
shape = a.shape
a = a.reshape(-1, 4)
return torch.cat((-a[:, :3... | 530eb2a8d8b9b87de2bfcaeb48729704908131cc | 14,132 |
import struct
def discard_blanks(data):
"""Remove blank spaces from the data file"""
pos = 0
for i_char in data:
char = struct.unpack('s', data[pos:pos + 1])[0].decode()
if char not in ["*", " "]:
break
else:
pos += 1
return data[pos:] | aff090ab188bffd6bca86eb3b861d25a0440dbcc | 14,135 |
def blank_lines(logical_line, blank_lines, indent_level, line_number,
previous_logical):
"""
Separate top-level function and class definitions with two blank lines.
Method definitions inside a class are separated by a single blank line.
Extra blank lines may be used (sparingly) to sepa... | 0f2d89ae662ffd39170e83f8788cf2946f7cd045 | 14,136 |
def gem_cov(frags, weight_flag):
"""
GEM coverage.
Args:
frags (list of list): [chrom,start,end] for each fragment in a GEM
weight_flag (binary): True if weighted by fragment number; False otherwise
Returns:
gem_all (list of bed entries): bed entries in format [chrom,start,end]
... | cd515d0f358992e07d9bf441c486ce088ce7c7a3 | 14,137 |
def unnormalise_density(c, rho):
"""Reverses any desnity normalisation
As a general rule this should be done using the units read in from the file,
with unit conversion done afterwards"""
return c * rho | 1ffa7b4f5e08a071d5f8e94489d363a085f31930 | 14,138 |
import random
def mutate_color(color):
"""
Mutates one coordinate of a color in a HSV cube.
"""
color[random.randrange(0, 3)] = random.random() % 1
return color | 5fdfef8b7c29be367dee85f195458924bb8421aa | 14,141 |
def container_with_most_water(heights):
"""
Parameters
----------
heights : list
A list of integers representing heights of containers
Returns
-------
int
area of container with most water
>>> container_with_most_water([1, 8, 6, 2, 5, 4, 8, 3, 7])
49
>>> conta... | d25c602bac1aab4484ca60680bcaa21abbb78dc7 | 14,143 |
import datetime as dt
import calendar
def _parse_date(row):
"""parse the date of a single row into datetime object."""
day_ix = 4; mon_ix = 5; year_ix = 6;
date = dt.date(int(row[year_ix]),
list(calendar.month_abbr).index(row[mon_ix]),
int(row[day_ix]))
del row[... | 51b3c86d98f2c7686b34fbae3dd1306e0f00f817 | 14,147 |
def shiny_gold_in(bag: str, rules: dict) -> bool:
"""Recursively check for shiny gold bags."""
if "shiny gold" in rules[bag].keys():
return True
elif not rules[bag]: # bag holds no others
return False
else:
for inner in rules[bag]:
if shiny_gold_in(inner, rules):
... | 1859f499b72a938a58a78af5ca1a78e9f7221731 | 14,148 |
def get_position_type(salary_plan):
"""
Given a salary plan code, map to one of the VIVO position types
"""
position_dict = {
'CPFI': 'postdoc',
'CTSY': 'courtesy-faculty',
'FA09': 'faculty',
'FA9M': 'clinical-faculty',
'FA10': 'faculty',
'FA12': 'faculty'... | eaaa64bfe35d27476eb9218d6401e0565126392d | 14,149 |
import ast
import logging
def _generate_trees(filename, with_filenames=False, with_file_content=False):
"""
Generated trees.
:param filename: filename
:param with_filenames: boolean
:param with_file_content: boolean
:return: list of ast object
"""
trees = []
with open(filename, 'r... | 258ccfabebb4de21d971939dfa3369a4658bace4 | 14,150 |
def str2ms(s):
"""
Convert the time strings from an SRT file to milliseconds.
Arguments:
s: A time value in the format HH:MM:SS,mmm where H, M, S and m are
digits.
Returns:
The time string converted to an integer value in milliseconds.
"""
s = s.strip()
time, ms ... | 552f9ffbd557cc0729c035901dc1a1a1bfae66d8 | 14,153 |
def parse(file):
"""parse out information from data_text and get information about image size, and class names"""
(str_height, str_width, str_names) = file.readlines()[0].split("*")
(height, width) = (int(str_height), int(str_width))
names = str_names.strip("][").replace("'", "").split(", ")
return... | 554bc1bf07671aecbe7da2ba2cfbb0bd51aa511c | 14,155 |
import torch
def get_device(inputs):
""" Get used device of a tensor or list of tensors. """
if isinstance(inputs, torch.Tensor):
device = inputs.device
elif isinstance(inputs, (tuple, list)):
device = inputs[0].device
else:
raise TypeError(f'Inputs can be a tensor or list of t... | eb67cb3a5ae226c4136bc172d37225ba6a64b45f | 14,157 |
def pythagorean_distance_equation(path1, path2):
"""Pythagorean Distance Equation.
Function for counting distance,
derived from the Pythagorean theorem.
"""
# point path dot X1
dotX1 = path1[0]
# point path dot X2
dotX2 = path2[0]
# point path dot Y1
dotY1 = path1[1]
# p... | a16f9d2a3f4ba824ebeb020ed2e5b1bb4068cc0e | 14,160 |
def quick_sort(sequence: list) -> list:
"""Simple implementation of the quick sort algorithm in Python
:param sequence: some mutable ordered collection with heterogeneous comparable items inside
:return: the same collection ordered by ascending
"""
if len(sequence) < 2:
return sequence
... | 73470224b8f149568b84c7b723097fc0c2ef353f | 14,161 |
def _is_gradient_task(task_id, num_tasks):
"""Returns True if this task should update the weights."""
if num_tasks < 3:
return True
return 0 <= task_id < 0.6 * num_tasks | 11d37b1095e40ef0be840c63a0c184e63630e945 | 14,162 |
def score_tup(t):
"""
Score an ngram tuple returned from a database ngram table. A higher scoring
term is more deserving of inclusion in the resulting acrostic
:param t: (Term string, initials string, Corpus count, Used count)
:return: Fitness score for this term
"""
term = t[0]
inits = ... | eea34dbf2d6a7dec37dc95cde289560a77c72f7e | 14,163 |
import torch
def get_optimizer(parameters, lr, weight_decay):
"""
Initiate Adam optimizer with fixed parameters
Args:
parameters: filter, parameters to optimize
lr: float, initial learning rate
weight_decay: float, between 0.0 and 1.0
Return:
a torch.optim.Adam optimizer
"""
return torch.optim.Adam(p... | 54b4c6a4cd02672ebfc8ff9c850f0d601fc6510f | 14,165 |
def DoesMoleculeContainsPAINSPattern(Mol, PAINSPatternMols):
"""Check presence of PAINS pattern in the molecule"""
MolMatched = False
for PatternMol in PAINSPatternMols:
if Mol.HasSubstructMatch(PatternMol, useChirality = True):
MolMatched = True
break
retu... | 15b8684b69c02508f24b075db654efcb4c903188 | 14,166 |
def encrypt_decrypt():
"""Decide whether to encrypt or decrypt."""
while True:
choice = input("Enter E for encryption or D for decryption:")
if choice == "E":
return "E"
elif choice == "D":
return "D"
else:
print("Wrong input! Please try again.... | 1361e86939cf333680ba9c640487bf246a8faf2d | 14,168 |
def get_P_Elc_toilet_seat_heater(theta_ave_d, P_Elc_toilet_seat_heater_rtd):
"""暖房時の消費電力を計算する
Parameters
----------
theta_ave_d : float
日付dにおける平均外気温度(地域、季節によらず 11.23), ℃
P_Elc_toilet_seat_heater_rtd : float
便座暖房時の定格消費電力, W
Returns
----------
P_Elc_toilet_se... | 48ca59bbf2ca88e4e93febb4c83c80564050757b | 14,169 |
def splunk_setup(splunk):
"""
Override this fixture in conftest.py, if any setup is required before the test session.
splunk fixture can provide the details of the splunk instance in dict format.
**Possible setups required**:
1. Enable Saved-searches before running the tests
2. Restart... | 88255ac6efd493cc6cb8cf6201ca1f9528534451 | 14,170 |
import requests
def get_gist(url):
""" Get gist contents from gist url.
Note the gist url display the raw gist instead of usual gist page.
Args:
url (str) : url containing the raw gist instead of usual gist page.
Returns:
(str): output gist str.
""... | 853623c31af246dc07e22ac8a7dd0b515a74a080 | 14,171 |
import struct
def encode_struct(fmt, value):
"""Generic method for encoding arbitrary python "struct" values"""
return struct.pack(fmt, value) | 57285e612f1f2798eceace6de7be0a71fd4520a0 | 14,172 |
import re
def is_email(addr):
"""
判断是否是合法邮箱
:param addr: 邮箱地址
:return: True or False
"""
re_is_email = re.compile("^[a-z0-9]+([._-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z]+$")
if re_is_email.search(addr):
return True
else:
return False | c48d931af7f57420d4b5829da02aa72203275f0f | 14,173 |
def merge_unique(a: list, b: list) -> set:
"""
merges all of the unique values of each list into a new set
>>> merge_unique([1, 2, 3], [3, 4, 5])
{1, 2, 3, 4, 5}
"""
ret = set()
a.extend(b)
for element in a:
ret.add(element)
return ret | 6a969c6beaee46e5618d25c5714cec223ebf1686 | 14,174 |
def get_wanted_parameter(season_data, names, index_para):
""" Take in a list of players' names, a wanted parameter and return
:param season_data: a dictionary of players' statistics
:param names: a list of players' names
:param index_para: index of the wanted parameter depending on the file
:return:... | 0d278abd79f28c922dfcacf4984af7efe14a9070 | 14,175 |
import argparse
def parse_args():
"""Parse args
:return: args
"""
parser = argparse.ArgumentParser(
description='Params for pulling aws instances for appetite')
parser.add_argument("-n", "--name-query", help="filter on name based on aws tag",
dest="name_query")
... | 8e5f1a67de324502ba801bfa9971e891c79fcbda | 14,176 |
import requests
def get_FREQ(
APIKey='AP8DA23',
FromDateTime='2021-01-01 00:01:00',
ToDateTime='2021-02-01 23:59:00',
ServiceType='csv',
endpoint='https://api.bmreports.com/BMRS/FREQ/v1'
):
"""Rolling System Frequency
"""
params = {
'APIKey': APIKey,
'FromDateTime... | 9e28b80f2b10c998047f10181cd6612a63392111 | 14,177 |
def cxDummy(ind1, ind2):
"""Dummy crossover that does nothing. This is used when we have a single gene in the chromosomes, such that
crossover would not change the population.
"""
return ind1, ind2 | d5a3667cb714663348d5f8f421c167e134eed612 | 14,178 |
def comtypes_get_refcount(ptr):
"""Helper function for testing: return the COM reference count of
a comtypes COM object"""
ptr.AddRef()
return ptr.Release() | d2e7addf5a4bfa497d46597f194bfaef48b129d7 | 14,179 |
def convert_cookie_str(_str):
"""
convert cookie str to dict
"""
_list = [i.strip() for i in _str.split(';')]
cookie_dict = dict()
for i in _list:
k, v = i.split('=', 1)
cookie_dict[k] = v
return cookie_dict | de6ada63afb3490e793a62e7de98460c48f3b1c8 | 14,180 |
def DL_ignore(answers):
"""Return False if any dictionary-learning method was selected.
Arguments
---------
answers: dict
Previous questions answers.
Returns
-------
bool
True if DL verbosity question should be ignored.
"""
expected = ['ITKrMM', 'wKSVD', 'BPFA']
... | fda853fc0f959dd5302a90bc9d56f012a1d7da8f | 14,183 |
def wait(status, timeout=None, *, poll_rate="DEPRECATED"):
"""(Blocking) wait for the status object to complete
Parameters
----------
status: StatusBase
A Status object
timeout: Union[Number, None], optional
Amount of time in seconds to wait. None disables, such that wait() will
... | 3311714c7aee5cbbecf658bfa563826c363752e2 | 14,186 |
import re
def find_md_links(md):
"""Returns dict of links in markdown:
'regular': [foo](some.url)
'footnotes': [foo][3]
[3]: some.url
"""
# https://stackoverflow.com/a/30738268/2755116
INLINE_LINK_RE = re.compile(r'\[([^\]]+)\]\(([^)]+)\)')
FOOTNOTE_LINK_TEXT_RE = re.compile(r'\[... | d630d22d571e774312516fc4005444087d23392f | 14,187 |
def sex(return_expectations=None):
"""
Returns M, F or empty string if unknown or other
"""
return "sex", locals() | 4f461d76d96f6c0559d20693b28280436af1a594 | 14,188 |
def epoch_time(start_time, end_time):
"""
Computes the time for each epoch in minutes and seconds.
:param start_time: start of the epoch
:param end_time: end of the epoch
:return: time in minutes and seconds
"""
elapsed_time = end_time - start_time
elapsed_mins = int(elapsed_time / 60)
... | 8265cb78c26a96a83a1035c09a7dccb0edf8c4d0 | 14,189 |
def fibonaccinumber(n):
"""
>>fibonaccinumber(6)
1 1 2 3 5 8
>>fibonaccinumber(10)
1 1 2 3 5 8 13 21 34 55
"""
if n<0:
print("Incorrect input")
elif n==0:
return 0
elif n==1:
return 1
else:
n1 , n2 =1,1
count = 1
w... | c69d23d2603360cba6b5d5e600da1aa96dcfec60 | 14,191 |
def play(pet) -> bool:
"""Return False if any of the stats is 0."""
if (not pet.hunger) or (not pet.thirst) or (not pet.energy) or (not pet.fitness) or (not pet.mental_health):
print("Oh no! Take better care of", pet.name, "next time!")
print("Thank you for playing!")
print(" - - - ")
... | 482b38868d402d40687ed0c7495a122c50783fe3 | 14,192 |
def base_prob(phred_score):
""" Returns the probabilty that a base is incorrect, given its
Phred score.
"""
prob = 10.0**(-float(phred_score)/10)
return prob | 8231019213204e65d577ea86d1e2e0e7352a3f70 | 14,193 |
import re
def need_format(line: str) -> bool:
"""
Return true if line as a title declaration followed by content
"""
return (
(
re.search("\t+e_\w*[-'\w]*\W*=", line) is not None
and re.search("\t+e_\w*[-'\w]*\W*=\W*{[\w\t]*\n", line) is None
and re.search("... | 61576aa02a745db8b0ce0c9c4c9a4d4589e8d842 | 14,195 |
import argparse
def parse():
"""
Handles the arguments and options.
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
"-w", "--what", dest="what",
help="REQUIRED - The absolute path to the folder containing the tests"... | ef1700cc5a3692fd5cd85d84cd24f37f859df7a7 | 14,196 |
def builderFor(action, hypervisor=None, template=None, service=None):
"""
This decorator is used to supply metadata for functions which is then used to find suitable methods
during building just by these properties.
:param action: Name of the generic step/action (see planner) that this function impleme... | 1dddfd8dc5dbc87e5a018fc4fb144bef8a8f98e3 | 14,197 |
def undeployed_value_only_calculator(repository, undeployed_value_tuple, deployed_value_tuple):
"""
Just return the undeployed value as the value.
This calculator can be used when there will be no deployed value.
"""
return undeployed_value_tuple[2] | 58294274d37b4c7bb9cad21bb01260986cb0d6ae | 14,198 |
import re
def _remove_inner_punctuation(string):
"""
If two strings are separated by & or -, remove
the symbol and join the strings.
Example
-------
>>> _remove_inner_punctuation("This is AT&T here")
'This is ATT here'
>>> _remove_inner_punctuation("A T & T")
'A T T'
"""
... | 4ca3e7f91e35dba2e0a34f1dfd935e004623875e | 14,199 |
def _scrape_main_synonym_section(left_content):
"""Scrapes the main/default synonym section for a word.
If there is no pos listed, use the one listed for the word
"""
synonym_header = left_content.find('div',
{'class' : 'synonyms_list'})
synonym_labels = synony... | 21063c652e733e6e6f6ca32bdf0d343bdbbb80f4 | 14,200 |
import re
def generateHashtags(randomTests):
"""Generates a hashtag from a level 1+ category name using Regular Expressions and other rules.
Arguments:
randomTests {Dictionary} -- A test category and hashtag (level 1+) categories
Returns:
Dictionary -- The input dictionary with added has... | 96478924f04706b88cb367d5aca334225771788b | 14,201 |
def get_longest_element(focus):
"""
cycles thru the status_results dictionary in the indicated key or field list and finds the
longest piece of text in it
:param focus: the key or field in value list that is being searched for longest value
:return: the longest value
"""
return (len(max(focu... | d00c02d3d02ebd371f16ef16fd2e7daa0ead47ac | 14,202 |
def get_num_classes(labels):
"""Get total number of classes.
Arguments:
labels {list} -- label values.
"""
num_classes = max(labels) + 1
missing_classes = []
for l in range(num_classes):
if l not in labels:
missing_classes.append(l)
if len(missing_classes):
... | 4573bbf81fab0396454167287e86492e0ee7cd48 | 14,203 |
def store_edges(edge_data):
"""Store edges in a dict where the keys are the edge times"""
time_edge_map = {}
for i in range(len(edge_data)):
current_time = edge_data[i,0]
if not current_time in time_edge_map:
time_edge_map[current_time] = []
time_edge_map[current_time].ap... | 885bb4f4e6480904a09bb7afe7d85053643a3f1a | 14,204 |
def filter_linker_flavour(args):
"""Remove `-flavor gnu`."""
new_args = []
ignore = False
for arg in args:
if ignore:
ignore = False # ignore this argument
else:
if arg == '-flavor':
ignore = True
else:
new_args.append(a... | f37aac3c7b14f25350c945c5258d851402292330 | 14,205 |
import random
def random_string(length, charset):
"""
Return a random string of the given length from the
given character set.
:param int length: The length of string to return
:param str charset: A string of characters to choose from
:returns: A random string
:rtype: str
"""
n = ... | 1370f86a2e696ba6030b719ec8e32631f1865e01 | 14,206 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.