content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
import re def parse_directory(filename): """ read html file (nook directory listing), return users as [{'name':..., 'username':...},...] """ try: file = open(filename) html = file.read() file.close() except: return [] users = [] for match in re.finditer(r'<b...
1b7fc5b6257b5c382f520a60c9227e8b458d482d
961
def countSort(alist): """计数排序""" if alist == []: return [] cntLstLen = max(alist) + 1 cntLst = [0] * cntLstLen for i in range(len(alist)): cntLst[alist[i]] += 1 #数据alist[i] = k就放在第k位 alist.clear() for i in range(cntLstLen): while cntLst[i] > 0: #将每个位置的数据k循环输出多次 ...
6727b41794dc2a2f826023c2a53202798dfa49ab
962
from datetime import datetime def get_default_date_stamp(): """ Returns the default date stamp as 'now', as an ISO Format string 'YYYY-MM-DD' :return: """ return datetime.now().strftime('%Y-%m-%d')
672cd98265b19da2df92c7849f1059e5988473d7
963
def get_physical_id(r_properties): """ Generated resource id """ bucket = r_properties['Bucket'] key = r_properties['Key'] return f's3://{bucket}/{key}'
2cd467d9b1df72a4573d99f7a5d799f9612239c9
965
def _rescale(vector): """Scale values in vector to the range [0, 1]. Args: vector: A list of real values. """ # Subtract min, making smallest value 0 min_val = min(vector) vector = [v - min_val for v in vector] # Divide by max, making largest value 1 max_val = float(max(vector)...
0091deb65c67ef55b2632ac8d5ff8a15b275d12e
966
def better_get_first_model_each_manufacturer(car_db): """Uses map function and lambda to avoid code with side effects.""" result = map(lambda x: x[0], car_db.values()) # convert map to list return list(result)
8969c23bfe4df2b1c164dca6c4f929a62de5ba2a
968
def parse_study(study): """Parse study Args: study (object): object from DICOMDIR level 1 object (children of patient_record) Returns: children_object appending_keys """ #study_id = study.StudyID study_date = study.StudyDate study_time = study.StudyTime ...
d0e85d991e4f2f13e6f2bd87c0823858ea9c83bc
969
import pickle def load_pickle(filename): """Load Pickfle file""" filehandler = open(filename, 'rb') return pickle.load(filehandler)
f93b13616f94c31bc2673232de14b834a8163c5f
970
import functools def pipe(*functions): """ pipes functions one by one in the provided order i.e. applies arg1, then arg2, then arg3, and so on if any arg is None, just skips it """ return functools.reduce( lambda f, g: lambda x: f(g(x)) if g else f(x), functions[::-1], ...
f58afedd5c7fe83edd605b12ca0e468657a78b56
971
def test_lambda_expressions(): """Lambda 表达式""" # 这个函数返回两个参数的和:lambda a, b: a+b # 与嵌套函数定义一样,lambda函数可以引用包含范围内的变量。 def make_increment_function(delta): """本例使用 lambda 表达式返回函数""" return lambda number: number + delta increment_function = make_increment_function(42) assert increm...
e727df25b2165bb0cd7c9cce47700e86d37a2a1a
973
import importlib def get_rec_attr(obj, attrstr): """Get attributes and do so recursively if needed""" if attrstr is None: return None if "." in attrstr: attrs = attrstr.split('.', maxsplit=1) if hasattr(obj, attrs[0]): obj = get_rec_attr(getattr(obj, attrs[0]), attrs[1]...
a6831d48c79b8c58542032385a5c56373fd45321
977
def _get_message_mapping(types: dict) -> dict: """ Return a mapping with the type as key, and the index number. :param types: a dictionary of types with the type name, and the message type :type types: dict :return: message mapping :rtype: dict """ message_mapping = {} entry_index = ...
a098e0386aa92c41d4d404154b0b2a87ce9365ce
978
import itertools def combinations(): """Produce all the combinations for different items.""" combined = itertools.combinations('ABC', r=2) combined = [''.join(possibility) for possibility in combined] return combined
501060cf9c7de9b4b4453940e017ad30cec2f84f
980
import os def _get_credentials(vcap_services, service_name=None): """Retrieves the credentials of the VCAP Service of the specified `service_name`. If `service_name` is not specified, it takes the information from STREAMING_ANALYTICS_SERVICE_NAME environment variable. Args: vcap_services (di...
a72f3e7b6be56ab6c66252cd8063fd0207aac02b
981
def is_str_str_dict(x): """Tests if something is a str:str dictionary""" return isinstance(x, dict) and all( isinstance(k, str) and isinstance(v, str) for k, v in x.items() )
ce6230714c0526764f2cc67e4dedf598acd28169
982
def _ensureListLike(item): """ Return the item if it is a list or tuple, otherwise add it to a list and return that. """ return item if (isinstance(item, list) or isinstance(item, tuple)) \ else [item]
1c602a1fcf8dd6a5b4583264e63e38747f5b0d50
983
import io def get_file_from_gitlab(gitpkg, path, ref="master"): """Retrieves a file from a Gitlab repository, returns a (StringIO) file.""" return io.StringIO(gitpkg.files.get(file_path=path, ref=ref).decode())
7eccad01a538bdd99651b0792aff150f73e82cdd
984
def mocked_requests_get(*args, **kwargs): """Mock requests.get invocations.""" class MockResponse: """Class to represent a mocked response.""" def __init__(self, json_data, status_code): """Initialize the mock response class.""" self.json_data = json_data sel...
41a54452593cd23e8ea86f1fbdc0c5e92845482f
985
def count_disordered(arr, size): """Counts the number of items that are out of the expected order (monotonous increase) in the given list.""" counter = 0 state = { "expected": next(item for item in range(size) if item in arr), "checked": [] } def advance_state(): state...
bb708e7d862ea55e81207cd7ee85e634675b3992
986
import json def json_io_dump(filename, data): """ Dumps the the JSON data and returns it as a dictionary from filename :arg filename <string> - Filename of json to point to :arg data - The already formatted data to dump to JSON """ with open(filename, encoding='utf-8', mode='w') as json_file: ...
e0ae7187ac29669330109ae39ebcac33c1e30ab6
987
import requests def reload_rules(testcase, rest_url): """ :param TestCase self: TestCase object :param str rest_url: http://host:port :rtype: dict """ resp = requests.get(rest_url + "/rest/reload").json() print("Reload rules response: {}".format(resp)) testcase.assertEqual(...
e747668ba8ad5f58f0307194b0008469dd3593c1
988
def subset_sum(arr, target_sum, i, cache): """ Returns whether any subset(not contiguous) of the array has sum equal to target sum. """ if target_sum == 0: return True, {} if i < 0: return False, {} if target_sum in cache[i]: return cache[i][target_sum] # Either inclu...
aa90d7eb4ffa3a457a5f27733de56a82df450861
989
def every(n_steps): """Returns True every n_steps, for use as *_at functions in various places.""" return lambda step: step % n_steps == 0
02fc6bc59fa6f223b681539baeae32c40bd9577e
991
def calc_batch_size(num_examples, batches_per_loop, batch_size): """Reduce the batch size if needed to cover all examples without a remainder.""" assert batch_size > 0 assert num_examples % batches_per_loop == 0 while num_examples % (batch_size * batches_per_loop) != 0: batch_size -= 1 return batch_size
3c394813a98a8414645f633a519001937247e8b0
992
def has_admin_access(user): """Check if a user has admin access.""" return user == 'admin'
d178861bee504f6f3026c9e495d56cc8d2d7c3d3
993
def flatten_mock_calls(mock): """ Flatten the calls performed on a particular mock object, into a list of calls with arguments. """ result = [] for call in mock.mock_calls: call = list(call) call_name = call[0] if '.' in str(call_name): call_name = str(call_na...
7c41025382f4ca25db1ccd328e9eb17e1d72a01a
995
def update_not_existing_kwargs(to_update, update_from): """ This function updates the keyword aguments from update_from in to_update, only if the keys are not set in to_update. This is used for updated kwargs from the default dicts. """ if to_update is None: to_update = {} to_update...
a66de151e6bc6d8f5b2f1b0ff32e30d2c8cb5277
996
def linear_forward(A, W, b): """Returns Z, (A, W, b)""" Z = (W @ A) + b cache = (A, W, b) return Z, cache
41d223473d2d8f084f13ca0f90f483b66e479a04
997
def piecewise_accel(duration,initial,final): """Defines a piecewise acceleration. Args: duration (float): Length of time for the acceleration to complete. initial (float): Initial value. final (float): Final value. """ a = (final-initial) return lambda t: initial + a * ( ...
7f6acd7ba2610a2e56cc1f0758b3a39543bfe8c2
999
def palindrome(d: int)-> str: """ Function is getting the digits of the number, left shifting it by multiplying it with 10 at each iteration and adding it the previous result. Input: Integer Output: String (Sentence telling if the number is palindrome or not) """ remainder = 0 revnum = 0...
fe654ab92a905e265987856bcd2106c7b082b490
1,000
from typing import List def add_multiple_package(package_list: List[str]) -> str: """ Generate latex code to add multiple package to preamble :param package_list: List of package to add in preamble """ usepackage_command_list = [] for package in package_list: usepackage_command_list.a...
90bdd0a521c094d92c35ef92e62d6b43f6b135b4
1,002
import sys def get_next_method(generator_instance): """ Cross-platform function that retrieves the 'next' method from a generator instance. :type generator_instance: Any :rtype: () -> Any """ if sys.version_info > (3, 0): return generator_instance.__next__ else: return ...
115bdd13c5afc74d1d5204d004c1034ae6438cb1
1,003
def commit_veto(environ, status, headers): """Veto a commit. This hook is called by repoze.tm in case we want to veto a commit for some reason. Return True to force a rollback. By default we veto if the response's status code is an error code. Override this method, or monkey patch the instancemeth...
9fc96fe8cdbedde20cb325e189b71d9df94cf176
1,004
def apply_to_all(func, results, datasets): """Apply the given function to all results Args: func: the function to apply results: nested dictionary where the nested levels are: algorithm name, sensitive attribute and split ID datasets: nested dictionary where the nested ...
6ea085b3541a84ac97f63389ba83c3a06d5e0b85
1,005
def any_value_except(mapping, excluded_keys): """Return a random value from a dict that is not associated with excluded_key. Raises StopIteration if there are no other keys than excluded_key""" return next(mapping[key] for key in mapping if key not in excluded_keys)
8d633713b93cfd1f0324d5c4a56a18fa7931ff06
1,006
import torch def one_hot(y, num_dim=10): """ One Hot Encoding, similar to `torch.eye(num_dim).index_select(dim=0, index=y)` :param y: N-dim tenser :param num_dim: do one-hot labeling from `0` to `num_dim-1` :return: shape = (batch_size, num_dim) """ one_hot_y = torch.zeros(y.size(0), num_d...
694bfea18ecbb5c5737e0d38c0aa0f5f52a82a55
1,007
import os def getProgFromFile(f): """Get program name from __file__. """ if f.endswith(".py"): f = f[:-3] return os.path.basename(f)
474c9b3f2bef2117daf8456d8b6f026d738182a1
1,009
def heuristic(node_1, node_2): """ Heuristic when only 4 directions are posible (Manhattan) """ (x_node_1, y_node_1) = node_1 (x_node_2, y_node_2) = node_2 return abs(x_node_1 - x_node_2) + abs(y_node_1 - y_node_2)
e431ed9d8a7acb34604b3e83c3f3d7774cd27d51
1,011
def extend_dict(x, *y): """Similar to Object.assign() / _.extend() in Javascript, using 'dict.update()' Args: x (dict): the base dict to merge into with 'update()' *y (dict, iter): any number of dictionary or iterable key/value pairs to be sequentially merged into 'x'. Skipped i...
f10a5bc7d5ed3646e6a9f8f9535a16bd800c7fcd
1,012
def print_hdr(soup, hdr, file = None): """ :param soup: [bs4.BeautifulSoup] document context :param hdr: [dict] header node to process :param file: [stream] I/O stream to print to :return: [stream] pass on the I/O stream so descent continues """ tag = hdr['tag'] tag_id = tag['id'] in...
2c6fd613a5c6ddb5ec842fb7cee845d1a8771ccd
1,014
def make_general_csv_rows(general_csv_dict): """ Method for make list of metrics from general metrics dict. Rows using in general metrics writer :param general_csv_dict: dict with all metrics :type general_csv_dict: dict :return: all metrics as rows :rtype: list """ rows = [] f...
45ca165d312b39cd0b7088e0bcbfb402a92e7e2b
1,015
def get_speakable_timestamp(timestamp): """Return a 'speakable' timestamp, e.g. 8am, noon, 9pm, etc.""" speakable = f"{timestamp.strftime('%I').lstrip('0')} {timestamp.strftime('%p')}" if speakable == '12 PM': return 'noon' elif speakable == '12 AM': return 'midnight' return speakab...
0b724686ebd5d3152d9017dc456d2945c78be0ee
1,016
import torch def _featurize(inputs,model): """ Helper function used to featurize exemplars before feeding into buffer. """ with torch.no_grad(): # Forward pass outputs = model(*inputs).detach() #Featurize raw exem return outputs
191fd1b362f38309a35618284fcf3f1910a06bd6
1,017
import pandas as pd import numpy as np def rm_standard_dev(var,window): """ Smoothed standard deviation """ print('\n\n-----------STARTED: Rolling std!\n\n') rollingstd = np.empty((var.shape)) for ens in range(var.shape[0]): for i in range(var.shape[2]): for j in ...
d37cfa3c756f8fc062a28ac078e4e16557282951
1,018
def make_file_prefix(run, component_name): """ Compose the run number and component name into string prefix to use with filenames. """ return "{}_{}".format(component_name, run)
73ef37d75d9e187ee49ee058958c3b8701185585
1,022
def parse_resolution(resolution): """ return: width, height, resolution """ resolution = resolution.strip() splits = resolution.split(',') return int(splits[0]), int(splits[1]), int(splits[2])
de937e440c4540d11cedd868e3f4a046baa99f22
1,023
import argparse def _parser() -> argparse.Namespace: """Take care of all the argparse stuff. :returns: the args """ # parser = GooeyParser(description='Remove : from data files') parser = argparse.ArgumentParser(description='Combines Nods using ') parser.add_argument('listspectra', help='List...
3edcefc24898d15fd67925729590710a4f0d1fb5
1,024
import base64 def multibase_b64decode(data): """ Follow forge's base64 urlsafe encode convention to decode string Args: data(string): encoded string Returns: bytes Examples: >>> multibase_b64decode('aGVsbG8') b'hello' """ if isinstance(data, str): data =...
fdbc0f937e33d7994737a3a515973598cac3debd
1,025
def filter_words(w_map, emb_array, ck_filenames): """ delete word in w_map but not in the current corpus """ vocab = set() for filename in ck_filenames: for line in open(filename, 'r'): if not (line.isspace() or (len(line) > 10 and line[0:10] == '-DOCSTART-')): line = lin...
efdef92093acf25c992dba86da25a4118ba728ec
1,028
def get_cache_template(sources, grids, geopackage, table_name="tiles"): """ Returns the cache template which is "controlled" settings for the application. The intent is to allow the user to configure certain things but impose specific behavior. :param sources: A name for the source :param grids: sp...
dc83a155d28e0b39f12a7dc7142b61a4bf27512b
1,029
def _row_key(row): """ :param row: a normalized row from STATEMENT_METRICS_QUERY :return: a tuple uniquely identifying this row """ return row['database_name'], row['user_name'], row['query_signature'], row['query_hash'], row['query_plan_hash']
2984e0e0b5fcc4e51a26af188e51fe65c52077a2
1,031
import hashlib def sha1_file(filename): """ Return the hex string representation of the SHA1 checksum of the filename """ s = hashlib.sha1() with open(filename, "rb") as f: for line in f: s.update(line) return s.hexdigest()
b993ac9f025d69124962905f87b1968617bb33f5
1,032
def read_from_file(file_path): """ Read a file and return a list with all the lines in the file """ file_in_list = [] with open(file_path, 'r') as f: for line in f.readlines(): file_in_list.append(line) return file_in_list
5fef3a3f50528c1a9786451666ae7e43be282bf9
1,033
def get_object_from_path(path): """ :param path: dot seperated path. Assumes last item is the object and first part is module path(str) - example: cls = get_object_from_path("a.module.somewhere.MyClass") you can create a path like this: class_path = "{0}.{1}".format...
e722b040486288d53fe4a357d81ddec8dfc9820e
1,034
def audio(src: str) -> str: """ Insert audio tag The tag is currently not supported by Nuance, please use `audio_player` kit: docs/use_kits_and_actions.md :param src: :return: """ return f'<audio src="{src}"/>'
f9396d5f82eeca27089de41187fd7d5e967cc9cf
1,037
import platform def is_windows_system(): """ | ##@函数目的: 获取系统是否为Windows | ##@参数说明:True or False | ##@返回值: | ##@函数逻辑: | ##@开发人:jhuang | ##@时间: """ return 'Windows' in platform.system()
6bfe296188b9dccf8338f0b2bbaaf146d9b22243
1,040
import sqlite3 def cn(DB): """Return the cursor and connection object.""" conn = sqlite3.connect(DB) c = conn.cursor() return (c,conn)
76abbec283d45732213f8b94031242146cdb4ee0
1,043
import copy def partially_matched_crossover(random, mom, dad, args): """Return the offspring of partially matched crossover on the candidates. This function performs partially matched crossover (PMX). This type of crossover assumes that candidates are composed of discrete values that are permutations...
b0d5132cf4ca14095f3d7c637cb50db3fe37d244
1,044
import re def regex_trim(input, regex, replace=''): """ Trims or replaces the regex match in an input string. input (string): the input string to search for matches regex (string): regex to match replace (string - optional): a string to replace any matches with. Defaults to trimming the match. """ return re.s...
169bfaa0d2bfd7a1f32c1e05a63b41993f82bf4b
1,045
def analytic_pi(x, c, w, h): """Analytic response function for an even pair of Lorentz distributions. Correspond to .. math:: \\Pi(x) = \\int_{-\infty}^{\\infty} \\frac{\\omega^2}{\\omega^2+x^2}\sigma()_{i} where :math:`\\sigma(\\omega)` is :func:`~even_lorentzian`. Args: x...
fc622e79a6692105c15e05ea353ba925b8378831
1,047
def prepare_definitions(defs, prefix=None): """ prepares definitions from a dictionary With a provided dictionary of definitions in key-value pairs and builds them into an definition list. For example, if a dictionary contains a key ``foo`` with a value ``bar``, the returns definitions will be a li...
ddc6d14cc18f8afba766efee65ab365df1d226c2
1,048
def extract_job_url(job): """ parse the job data and extract the str for the URL of the job posted params: job str: html str representation from bs4 returns: url str: relative URL path of the job ad """ return job.a["href"]
7517badcc2814e641c04a8f880353d897d434b7f
1,049
def create_patric_boolean_dict(genome_dict,all_ECs): """ Create new dict of dicts to store genome names :param genome_dict: dict of key=genome_id, value=dict of genome's name, id, ec_numbers :param all_ECs: set of all ECs found across all genomes """ ## new format: key=genome, value={EC:0 or 1}...
7ab3554bbf705ee8ce99d1d99ff453b06e3d2b53
1,050
def append_ast_if_req(field): """ Adds a new filter to template tags that for use in templates. Used by writing {{ field | append_ast_if_req }} @register registers the filter into the django template library so it can be used in template. :param Form.field field: a field of a form that you woul...
76e36ead3387729b0536bf84f288c400f376a041
1,051
def getPileupMixingModules(process): """ Method returns two lists: 1) list of mixing modules ("MixingModule") 2) list of data mixing modules ("DataMixingModules") The first gets added only pileup files of type "mc", the second pileup files of type "data". """ mixModules, dataMixModules = [], [] ...
4ee3cc5f7b11e4ad6a846f14dc99e4f82bd04905
1,052
import random def check_random_state(seed): """ Turn seed into a random.Random instance If seed is None, return the Random singleton used by random. If seed is an int, return a new Random instance seeded with seed. If seed is already a Random instance, return it. Otherwise raise ValueError. ...
347481de01f4a3bba59bc9a2c484c10d4857e1e2
1,055
def chunk(seq, size, groupByList=True): """Returns list of lists/tuples broken up by size input""" func = tuple if groupByList: func = list return [func(seq[i:i + size]) for i in range(0, len(seq), size)]
e7cece99822a01476b46351cebc1345793485cbd
1,056
def definition(): """ Lists the parent-child relationships through the curriculum structure. """ sql = """ --Course to session SELECT c.course_id as parent_id, CASE WHEN cc.course_id IS NULL THEN 0 ELSE 1 END as linked, cs.course_session_id as child_id, 'course' as parent, cs.description + ' ' + ...
e8dc6a720dcd5f62854ce95e708a88b43859e2cc
1,057
def bilin(x, y, data, datax, datay): # --DC """ x, y ARE COORDS OF INTEREST data IS 2x2 ARRAY CONTAINING NEARBY DATA datax, datay CONTAINS x & y COORDS OF NEARBY DATA""" lavg = ( (y - datay[0]) * data[1,0] + (datay[1] - y) * data[0,0] ) / (datay[1] - datay[0]) ravg = ( (y - datay[0]) * data[1,1] + ...
59a740f65c7187a08cdc09cef8aa100b01c652cf
1,058
def biosample_table_data(): """Return a dictionary containing the expected values of the BioSample Table""" columns = [ "id", "BioSample_id", "BioSampleAccession", "BioSampleAccessionSecondary", "BioSampleBioProjectAccession", "BioSampleSRAAccession", "Bi...
65e5d5bb5416a8f113100562fba8f2e6fd66796a
1,059
def get_user_playlists(spotipy_obj, username): """Gets and returns all Spotify playlists owned by the username specified. Parameters: spotipy_obj: Spotipy object username: Spotify username Returns: List of dictionaries, each dictionary a Spotify playlist object. """ # Gra...
90c06e0ddd91a7a84f4d905dd9334f9b4c27f890
1,060
def compute_median_survival_time(times, surv_function): """ Computes a median survival time estimate by looking for where the survival function crosses 1/2. Parameters ---------- times : 1D numpy array Sorted list of unique times (in ascending order). surv_function : 1D numpy array...
22103bc705acb791c0937a403aa9c34e9145e1c2
1,063
def aggregate_ant(data, sub_num, response_type="full"): """ Aggregate data from the ANT task. Calculates various summary statistics for the ANT task for a given subject. Parameters ---------- data : dataframe Pandas dataframe containing a single subjects trial data for the task. su...
be01651d450560a5c36bc6240025fe59352d6347
1,064
import re def url_validate(url): """ URL验证 用于登录传递URL """ regex = r'^\?next=((/\w+)*)' if isinstance(url, str) and re.match(regex, url): return url.split('?next=')[-1] return '/'
7a5aa5866018d1bf16c0f4ede527a770da760e17
1,065
def _build_tags(model_uri, model_python_version=None, user_tags=None): """ :param model_uri: URI to the MLflow model. :param model_python_version: The version of Python that was used to train the model, if the model was trained in Python. :param user_tags: A collection o...
8807967b3e9d89dbb7a24542d2709bc9293992df
1,067
from typing import Tuple def unsorted_array(arr: list) -> Tuple[list, int, Tuple[int, int]]: """ Time Complexity: O(n) """ start, end = 0, len(arr) - 1 while start < end and arr[start] < arr[start + 1]: start += 1 while start < end and arr[end] > arr[end - 1]: end -= 1 f...
c3370a3e76009ef26ae3e1086e773463c312c6bb
1,068
def get_tol_values(places): # type: (float) -> list """List of tolerances to test Returns: list[tuple[float, float]] -- [(abs_tol, rel_tol)] """ abs_tol = 1.1 / pow(10, places) return [(None, None), (abs_tol, None)]
5af82438abbc0889374d62181ca7f0b7ee3c0fbe
1,069
def ipv4_size_check(ipv4_long): """size chek ipv4 decimal Args: ipv4_long (int): ipv4 decimal Returns: boole: valid: True """ if type(ipv4_long) is not int: return False elif 0 <= ipv4_long <= 4294967295: return True else: return False
97c5d5c7472fb81e280f91275b5a88b032ee7927
1,070
def display_ordinal_value(glyph: str): """Displays the integer value of the given glyph Examples: >>> display_ordinal_value('🐍')\n 128013 >>> display_ordinal_value('G')\n 71 >>> display_ordinal_value('g')\n 103 """ return ord(glyph)
7daa53180023bfec2968308d463ac615a83a4e55
1,072
def _without_command(results): """A helper to tune up results so that they lack 'command' which is guaranteed to differ between different cmd types """ out = [] for r in results: r = r.copy() r.pop('command') out.append(r) return out
67927cf56884e0e3b22d0daf37e6c02eaef3849b
1,073
def print_tree(tree, level=0, current=False): """Pretty-print a dictionary configuration `tree`""" pre = ' ' * level msg = '' for k, v in tree.items(): if k == 'self': msg += print_tree(v, level) continue # Detect subdevice if isinstance(v, dict) and 'se...
f9697b506e9254b4982a037bdfbeb8a1d27f35bb
1,077
def chaine_polynome(poly): """Renvoie la représentation dy polynôme _poly_ (version simple)""" tab_str = [str(coef) + "*X^" + str(i) if i != 0 else str(coef) for i,coef in enumerate(poly)] return " + ".join(tab_str[::-1])
79fd59afe84c1bd12e3417b9195514664d1bce20
1,078
import re def tokens(s): """Return a list of strings containing individual words from string s. This function splits on whitespace transitions, and captures apostrophes (for contractions). >>> tokens("I'm fine, how are you?") ["I'm", 'fine', 'how', 'are', 'you'] """ words = re.findall(r...
aee0b6fad2f9107c893496f1f3807e80c9d2e44b
1,079
def median(list_in): """ Calculates the median of the data :param list_in: A list :return: float """ list_in.sort() half = int(len(list_in) / 2) if len(list_in) % 2 != 0: return float(list_in[half]) elif len(list_in) % 2 ==0: value = (list_in[half - 1] + list_in[half...
261487551098b80986cbfb8e4cd28279649ac456
1,080
from typing import Dict from typing import List from typing import Set from typing import Any from functools import reduce def get_set_from_dict_from_dict( instance: Dict[str, Dict[str, List]], field: str ) -> Set[Any]: """ Format of template field within payload Function gets field from instance-dict...
75ee6f4d46a4f57012e76b0f02fb20f629b6bf60
1,082
def Get_Unread_Messages(service, userId): """Retrieves all unread messages with attachments, returns list of message ids. Args: service: Authorized Gmail API service instance. userId: User's email address. The special value "me". can be used to indicate the authenticate...
2aa28ff1aa093754bd293a831be2dada0e629801
1,083
def potatoes(p0, w0, p1): """ - p1/100 = water1 / water1 + (1 - p0/100) * w0 => water1 = w0 * p1/100 * (1 - p0/100) / (1 - p1/100) - dry = w0 * (1 - p0/100) - w1 = water1 + dry = w0 * (100 - p0) / (100 - p1) Example: 98/100 = water1 / water1 + (1- 99/100) * 100 water1 = 49 w1 = 49...
f2955a58db3a48c64b6acc4980e663f33332aeea
1,084
import re def get_sale(this_line, cattle, category): """Convert the input into a dictionary, with keys matching the CSV column headers in the scrape_util module. """ cattle = cattle.replace("MARKET","") cattle = cattle.replace(":","") cattle = cattle.strip().title() sale = {'cattle_cattle'...
f75e949558c9938a44f64ccce11bacce8d116e9f
1,085
import os import requests def get_request(term, destination, days_input, price_limit, food_preference): """ Fetches restaurant information from the Yelp API for a given meal term, meal attribute, destination, number of days of vacation, price limit, and food preference. Params: term (str) the spe...
df9b5a2534278963dc5fa0719db3f915ce8fcb8d
1,086
def relacao(lista): """Crie uma função que recebe uma lista de números reais e retorna uma outra lista de tamanho 3 em que (i) o primeiro elemento é a quantidade de números maiores que zero, (ii) o segundo elemento é a quantidade de números menores que zero e (iii) o último elemento é a quantidade de...
39e45d8221d5d5b7322ebec5aa3f761d9e2ef413
1,087
def fit_slice(fitter, sliceid, lbda_range=[5000, 8000], nslices=5, **kwargs): """ """ fitvalues = fitter.fit_slice(lbda_ranges=lbda_range, metaslices=nslices, sliceid=sliceid, **kwargs) return fitvalues
2d2b4b91b0ba3b0dca908d56e8b5184e5ae36b9e
1,088
def german_weekday_name(date): """Return the german weekday name for a given date.""" days = [u'Montag', u'Dienstag', u'Mittwoch', u'Donnerstag', u'Freitag', u'Samstag', u'Sonntag'] return days[date.weekday()]
7d2919c61438ec913abe38cccd924bb69f866655
1,089
def identity_func(x): """The identify (a.k.a. transparent) function that returns it's input as is.""" return x
06e0296c338d68663aa87d08b21f84919be3f85e
1,090
def make_choice_validator( choices, default_key=None, normalizer=None): """ Returns a callable that accepts the choices provided. Choices should be provided as a list of 2-tuples, where the first element is a string that should match user input (the key); the second being the value associat...
65ac672f16a1031a9051bc4f6769c6b1b88db727
1,091
def gen_event_type_entry_str(event_type_name, event_type, event_config): """ return string like: {"cpu-cycles", PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES}, """ return '{"%s", %s, %s},\n' % (event_type_name, event_type, event_config)
ca89c19b45f182b8a7ae74ab76f3f42bddf46811
1,092
from pathlib import Path def get_force_charge() -> str: """ Gets the command object for the force charge command Returns: The command object as a json string """ force_charge = Path('force_charge.json').read_text() return force_charge
c67277c62664419c3b4a19ae57ea6de027c60416
1,093
def xor_columns(col, parity): """ XOR a column with the parity values from the state """ result = [] for i in range(len(col)): result.append(col[i] ^ parity[i]) return result
2eff4dbf3edf2b97410e7bef17c043a30b1f3aa8
1,094
def _non_string_elements(x): """ Simple helper to check that all values of x are string. Returns all non string elements as (position, element). :param x: Iterable :return: [(int, !String), ...] """ problems = [] for i in range(0, len(x)): if not isinstance(x[i], str): p...
974715622949157693084823a52a88973b51d100
1,095
def config_entry_version_fixture(): """Define a config entry version fixture.""" return 2
cac78c1f02668c95ce918d6219cadd5f08ab21c9
1,096
def get_filename_pair(filename): """ Given the name of a VASF data file (*.rsd) or parameter file (*.rsp) return a tuple of (parameters_filename, data_filename). It doesn't matter if the filename is a fully qualified path or not. - assumes extensions are all caps or all lower """ param_file...
f6eb5a64cf472f230c5806447d9c2ee8ae43a71d
1,097