content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def isbn13to10(isbn13: str) -> str: """ Convert ISBN-13 to ISBN-10 (without checking validity of input). """ isbn9 = isbn13[3:12] # for the checksum, isbn9 is zipped with [10, 9, ... 2] weights = range(10, 1, -1) checksum: int = sum(weight * int(digit) for weight, digit in zip(weights, isbn9...
85c0f305ab35e36ac74463b4ddcfc1fa3ed4bacf
304,960
def hex_to_rgb(value): """Hex value to (r, g, b) triple. """ return [((value >> (8 * k)) & 255) / 255.0 for k in (2, 1, 0)]
43adea9f3ad15ee25843bd810d4ce26a314a7d07
372,252
from typing import List def parse_config_lines(raw: str) -> List[str]: """Returns the lines in a config section.""" return [x for x in raw.split("\n") if x]
960381e362dc7e0743e4526fb772bae62c5ffe0e
594,464
def key( *args ): """ join the arguments in the format of donkey Arguments --------- args: list of string Examples -------- >>>key( 'a', 'b', 'c' ) 'a__b__c' """ return '__'.join( args )
9094dd19fd221073fe9cdac84a3616e71eb6fbcc
649,440
def strike_text(text): """Add a strikethtough effect to text.""" striked = '' for char in text: striked = striked + char + '\u0336' return striked
22a404f58ea07a1d08e0af6f1f450156f34c8f13
519,002
import torch def xywh2YOLO(box: torch.Tensor, stride: float, anchor: tuple): """ Returns the bounding box in a format similar to the last output layer of the YOLO Arguments: box (torch.Tensor): Boudning box tensor in xywh format stride (float): stride...
74ad50f5d61b206d53469020a53aafcb5eb29533
246,181
def flipHit(hit): """Returns a new hit where query and subject are flipped""" return [hit[1], # 0. Query id, hit[0], # 1. Subject id, hit[2], # 2. % identity, hit[3], # 3. alignment length, hit[4], # 4. mismatches, hit[5], # 5. gap op...
34543613ae229b2d68734c903656814a0db19a51
237,486
def binary_freq(data, expression, feature_name=str, analyze=True): """Search data for occurrences of a binary feature as a regex. Args: data (pd.Series): a series with text instances. expression (re.compile): a regex or string to search for. feature_name (str, optional): a name for the...
3211b7bfb37aae912816e81f8eb92792afd7a4e1
676,425
def _spectrogram_mp_helper(ooi_hyd_data_obj, win, L, avg_time, overlap, verbose, average_type): """ Helper function for compute_spectrogram_mp """ ooi_hyd_data_obj.compute_spectrogram(win, L, avg_time, overlap, verbose, average_type) return ooi_hyd_data_obj.spectrogram
759fc929df6309f8fd48d668a66c6dfe473dcb46
554,726
def get_and_update_or_create(model, filter_params, defaults): """ get or create with default values applied to existing instances {model}.objects.get_or_create(*{filter_params}, defaults={defaults}) Arguments: model {django.db.models.Model} -- The model the queryset gets applied to fil...
3bea14911f6a690606813aa29caa8a463918564a
632,838
def isUnivariate(signal): """ Returns True if `signal` contains univariate samples. Parameters ---------- signal : np.array, shape (NUM_SAMPLES, NUM_DIMS) Returns ------- is_univariate : bool """ if len(signal.shape) == 1: return True if signal.shape[1] > 1: re...
d282ed739526e4ecdd17e5ca429e037ee56415e3
165,230
def replace_all(text, dic): """ replaces multiple strings based on a dictionary replace_all(string,dictionary) -> string """ for i, j in dic.items(): text = text.replace(i, str(j)) return text
cbfde8ed2bfc8273ec7f4618a8067fe394b6ae9e
185,501
def remove_stopwords(texts, stop_words): """ Parameters: - `texts` a list of documents - `stop_words` a list of words to be removed from each document in `texts` Returns: a list of documents that does not contain any element of `stop_words` """ return [[w...
b70828b328abe1e0e59698307adc8ececeac368e
688,922
def trim_variable_postfixes(scope_str): """Trims any extra numbers added to a tensorflow scope string. Necessary to align variables in graph and checkpoint Args: scope_str: Tensorflow variable scope string. Returns: Scope string with extra numbers trimmed off. """ idx = scope_str.find(':') retur...
eb4d4dc14d903129a7dcddd2df7419724aed425a
117,090
def removeall(item, seq): """Return a copy of seq (or string) with all occurences of item removed.""" if isinstance(seq, str): return seq.replace(item, '') else: return [x for x in seq if x != item]
96f47b79c9f23fe84e873339d7ee49595006bb0c
306,325
def get_triangulars(num): """ Get the first n triangular numbers. """ return [int(i * (i + 1) / 2) for i in range(1, num + 1)]
35071a218c49609085a6c26c067fcee481b24f3d
530,988
def _to_str(pvs): """Ensure argument is a string or list of strings.""" # The logic follows that from the cothread library. # If is it NOT a string then assume it is an iterable. if isinstance(pvs, str): return str(pvs) else: return [str(pv) for pv in pvs]
dea36c6b7b402190f38a2d89ebc6478b337a28db
447,457
def set_name_line(hole_lines, name): """Define the label of each line of the hole Parameters ---------- hole_lines: list a list of line object of the slot name: str the name to give to the line Returns ------- hole_lines: list List of line object with label ...
a57667f269dac62d39fa127b2a4bcd438a8a989b
705,895
def capitalize_first_letter(text): """ Given a string, capitalize the first letter. """ chars = list(text.strip()) chars[0] = chars[0].upper() return "".join(chars)
c690a4e8392d7eedbc539c800c69e9addb60d0ef
219,205
def main(spark, file_path, subsampling=1): """ This function splits a dataframe into the train/valid/test set. - train: randomly sample 60% of users and include all of their interactions + 50% of interactions from users in the valid/test set - valid: randomly sample 20% of users and...
d6096392c0ef965f4cd16b37eddf8e6f34e0d572
472,427
from bs4 import BeautifulSoup def getNewData(response): """Extracts hidden input data from a response, returning a data dictionary. Extracts hidden input data from a response body, returning a dictionary of key-value pairs representing data to send to subsequent requests. Args: response: The Python re...
5cc2dab183d5aea69d0afeac68879ebaaa8b637a
351,215
def gcs_url_for_backup_directory(backup_bucket_name, fuzzer_name, project_qualified_target_name): """Build GCS URL for corpus backup directory. Returns: A string giving the GCS URL. """ return 'gs://%s/corpus/%s/%s/' % (backup_bucket_name, fuzzer_name, ...
85ac9d935515dda426d4579112733e9e8f5f1e09
231,026
def read_parameters_dict_lines_from_file_header( outfile, comments="#", strip_spaces=True ): """Load a list of pretty-printed parameters dictionary lines from a commented file header. Returns a list of lines from a commented file header that match the pretty-printed parameters dictionary format as ...
6f06fade43b69da083b95b4ddc0d10f168779118
63,732
def resize_quota_delta(context, new_flavor, old_flavor, sense, compare): """Calculate any quota adjustment required at a particular point in the resize cycle. :param context: the request context :param new_flavor: the target instance type :param old_flavor: the original instance type :param sen...
25d65a5e60ab6665674dfb47ca2c573861432fc1
93,419
def align2local(seq): """ Returns list such that 'ATG---CTG-CG' ==> [0,1,2,2,2,3,4,5,5,6,7] Used to go from align -> local space """ i = -1 lookup = [] for c in seq: if c != "-": i += 1 lookup.append(i) return lookup
aa914a60d5db7801a3cf1f40e713e95c98cd647e
3,313
def subset_sum_squeeze(data, subset={}, sum_dims=None, squeeze=False): """ Take an xarray DataArray and apply indexing, summing and squeezing, to prepare it for analysis. Parameters ---------- data : xarray DataArray A Calliope model data variable, either input or output, which has been...
182c8ddab3642c5fe9bec8520cbc5badb43b8f4e
664,566
def intersect(list1, list2) -> bool: """Do list1 and list2 intersect""" if len(set(list1).intersection(set(list2))) == 0: return False return True
78ce4dc472e621d5fe950bc0446b05372fda31b3
155,248
def remove_tweet_id(tweet): """ DESCRIPTION: removes the id from a string that contains an id and a tweet e.g "<id>,<tweet>" returns "<tweet>" INPUT: tweet: a python string which contains an id concatinated with a tweet of the following format: "<id>,...
be9d6f8481c735574763888ab4db8d5b0627320f
234,166
def read_lwostring(raw_name): """Parse a zero-padded string.""" i = raw_name.find(b'\0') name_len = i + 1 if name_len % 2 == 1: # Test for oddness. name_len += 1 if i > 0: # Some plugins put non-text strings in the tags chunk. name = raw_name[0:i].decode("utf-8", "ignore"...
d22fc8ddf6b1ca5f3e855cc45c5debd0f1ac4e54
493,499
def send_typed_media(resource_path, bot, channel): """Send file as bytes by `resource_path`. Send type based on file extension.""" ext = resource_path.suffix.lower() media_resource = open(resource_path, 'rb') if ext in ('.jpeg', '.jpg', '.png'): return bot.send_photo(chat_id=channel, photo=...
285f49f5078fafef7d14eb1d71c89cac6511a62c
500,249
def get_appliance_software_version( self, ne_pk: str, cached: bool, ) -> list: """Get appliance software version information .. list-table:: :header-rows: 1 * - Swagger Section - Method - Endpoint * - appliancesSoftwareVersions - GET ...
8d5ef977893d48480d194985cc2e15d51edaac71
535,152
from typing import MutableMapping from typing import Any def walk_the_tree(tree: MutableMapping[str, Any], stem: list[str] = []) -> list[list[str]]: """Return the leaves of the branches.""" leaves = [] for branch, branches in tree.items(): leaf = stem + [branch, ] if isinstance(branches, d...
76bddf00a649ebd5070c1df87a727210696e8eab
478,137
def enum(*args, **kwargs): """ Create an enumeration having the given values. As the concept of enumeration does not exist in python, this will actually create a new type, like a class that is not instanciated (and has no reason to be). The class will hold a class attribute for each possible value ...
f06ad6302b326a778acf88d860bb1e43849f8942
547,339
def getEditDistance(str1, str2): """Return the edit distance between two strings. >>> getEditDistance("abc", "abcd") 1 >>> getEditDistance("abc", "aacd") 2 If one of the strings is empty, it will return the length of the other string >>> getEditDistance("abc", "") 3 ...
9e03ba29f26017990e131ea6485bf3885975c28d
82,431
def is_prop(value): """Check whether a field is a property of an object""" return isinstance(value, property)
9cdf553e229f72c5f1cbe587646669000665d676
297,691
def string_list(argument): """ Converts a space- or comma-separated list of values into a python list of strings. (Directive option conversion function) Based in positive_int_list of docutils.parsers.rst.directives """ if ',' in argument: entries = argument.split(',') else: ...
ca6e7eba4e750f220915a61ca9ee0e25abb1ce03
324,066
def overlaps(when, spans): """ Checks an overlap of a datetime with list of datetime spans. """ for start, stop in spans: if start <= when <= stop: return True return False
58a5b09e093224ae1d67257f00986c43a3c1f63c
74,412
from typing import Tuple def _pos_from_offset(col: int, msg: bytes, offset: int) -> Tuple[int, int]: """Calculate the line and column of a given offset.""" msg = msg[:offset] lines = msg.split(b"\n") line = len(lines) - 1 col = len(lines[-1]) + (col if line == 0 else 0) return (line, col)
01c9f35e94443b028308d3129e774b777d393723
498,879
def factorialTrailingZeros(n): """ Function to count the number of trailing 0s in a factorial number. Parameters: n (int); the number for which the factorial and trailing 0s are to be calculated. Returns: trailingZeros (int); the number of 0s in the calculated factorial number. """ ...
86a17c160ff8d14a934fbd77bfa8f925fc1a1124
112,880
def install_conda_target(conda_target, conda_context, skip_environment=False): """ Install specified target into a its own environment. Return the process exit code (i.e. 0 in case of success). """ if not skip_environment: create_args = [ "--name", conda_target.install_environme...
3daf3dc55fab83c4da9b749bd2dcce537b091b12
120,854
import asyncio import functools def aio_run(func): """ Decorate an async function to run as a normal blocking function. The async function will be executed in the currently running event loop (or automatically create one if none exists). Example: .. code-block:: async def coroutine(...
768df2de0ef06f5e87560a61689710a84d397214
372,533
from pathlib import Path def clean_path(path): """ Cleans the path to allow it to be used to search with glob. It does a few different things: - Replaces ~ with the users home directory. - Makes sure the path ends with a / param: path: The path to clean. returns: The cleaned path. ""...
5ac069f9791f1a953926a553e4690ca1c6f01339
136,828
def rename_coords_to_lon_and_lat(ds): """ Rename Dataset spatial coord names to: lat, lon """ if 'latitude' in ds.coords: ds = ds.rename({'latitude': 'lat'}) if 'longitude' in ds.coords: ds = ds.rename({'longitude': 'lon'}) elif 'long' in ds.coords: ds = ds.rename({'l...
8ba286e441f2a32a96fbbddc5c1112a6ed890f84
16,652
import re from typing import Counter def _get_table_width(table_spec): """Calculate the width of a table based on its spec. :param table_spec: :type table_spec: str :return: :rtype: int """ column_letters = ['l', 'c', 'r', 'p', 'm', 'b'] # Remove things like {\bfseries} cleane...
97764d26434fbbcd1564538fe60d789059631a7a
517,986
import pickle def serialize(x): """Return a pickled object.""" return pickle.dumps(x)
c3debbc8df9b457879a784344ab7885b95b9ecd3
628,259
def format_number_latex(number: float, sig_figures: int = 3) -> str: """ Formats the number in latex format and round it to defined significant figures. If the result is in the exponential format, it will be formatted as ``[number] \\times 10^{[exponent]}``. Parameters ---------- number : ...
4891a78b10640022bb732c2e94c1a2e0ae72232f
543,545
def addresses(intcodes, ip): """ Return the three address (a, b, c) at positions 1,2,3 past ip. """ return intcodes[ip+1 : ip+4]
585f789ba5d095af20d87374c7f2ed8d1b2a3770
515,159
def color_normalization(image, mean, stddev): """ Perform color normalization on the image with the given mean and stddev. Args: image (ndarray): image to perform color normalization. mean (ndarray): mean value to subtract. dtype is 'float' stddev (ndarray): stddev to devide. """...
4bcd8b89560138d709a727bd5020aef275ece119
452,088
import re def remove_slash(value): """ Removes slash from beginning and end of a string """ assert isinstance(value, str) return re.sub('(^\/|\/$)', '', value)
1227d83c37acde1c71d24c9ac12056af6f501004
384,878
from typing import OrderedDict def dict_to_table(dct, titles=('col1', 'col2'), margin=3, sort=True): """ Formats a dict where key:val is str:str into a two column table. """ if sort: dct = OrderedDict({key: dct[key] for key in sorted(dct.keys())}) col1width = max([len(str(s)) for s in dct....
4955301143c7247d82f6ae50e30b9114af798ff6
308,753
def is_all_nan(tensor): """ Checks if all entries of a tensor is nan. """ return (tensor != tensor).all()
c181bee59308a85c8b6797c8e8319b7dc4f2e0fa
545,361
def only_dna(seq: str) -> str: """Return ``str`` with all ACGTN characters from ``seq``.""" return "".join(filter(lambda x: x in "ACGTNacgtn", seq))
b2c067bc9ace2a84fedc3e694a1fc54b076a3906
540,289
def stray(arr): """ You are given an odd-length array of integers, in which all of them are the same, except for one single number. :param arr: an array of integers. :return: the single different number in the array. """ a, b = set(arr) return a if arr.count(a) == 1 else b
17e99c2d22baceb89c16c01a138896918ab3a9e6
664,833
import torch def count_duplicates(cover_index: torch.LongTensor, normalize=False): """Count the number of node repetitions in the cover sets. Args: cover_index (torch.LongTensor): Cover assignment matrix, in sparse coordinate form. normalize (bool, optional): Normalize the re...
bb53f6d5ae2af7cce980bacd95277837aac65953
588,774
def t03_SharingIsPassByReference(C, pks, crypto, server): """Verifies that updates to a file are sent to all other users who have that file.""" alice = C("alice") bob = C("bob") alice.upload("k", "v") m = alice.share("bob", "k") bob.receive_share("alice", "k", m) score = bob.download("k"...
ffdcde1c6dd9fcb6053715789287efabbe7ed6f1
678,163
def _get_first_msgtype(elem): """Returns type identifier for this transaction""" return elem["tx"]["value"]["msg"][0]["type"]
80ebbfa07609ef673dabd16f8881d1e9562b4eb0
519,319
from datetime import datetime def parse_date(date_string, format='%Y-%m-%d'): """ parse a date string :param date_string: a string representing a date :param format: format of the string, default to '%Y-%m-%d' :return: a date object """ return datetime.strptime(date_string, format).date()
860e327bbeefd703708900d703016d8981e5c514
485,186
from typing import List def filter_out_trivial_gotos(disasm: List[str]) -> List[str]: """Filter out gotos to the next opcode (they are no-ops).""" res = [] # type: List[str] for i, s in enumerate(disasm): if s.startswith(' goto '): label = s.split()[1] if i + 1 < len(dis...
81bba9e6abd6f5e58ae214be46774f875996e3b5
262,684
from typing import Sequence def pool_keep_low(pool: Sequence[int], keep: int) -> tuple[int, ...]: """Keep a number of the lowest dice.""" pool = list(pool) remove = len(pool) - keep for _ in range(remove): high_value = min(pool) high_index = 0 for i, n in enumerate(pool): ...
b8c5877767c246191c972756f151b3ce41e45b3b
197,205
def curtail_string(s, length=20): """Trim a string nicely to length.""" if len(s) > length: return s[:length] + "..." else: return s
48b6624983b810517651d89185761210ba95ad27
669,629
def source_link_type(url): """ Get an URL and will return the URL type for display the true text in the wiki view. :param url: Ruleset source's URL :type url: str :return: A string of URL type (github, patreon or unknown) """ if ("github.com" or "www.github.com") in url: result = "...
65f2984e612887b75635885bf674d6c2f5360fb9
358,017
def TypeCodeToType(typeCode): """ Convert a type code to the class it represents """ if typeCode in ["b", "d", "f", "s"]: return float elif typeCode in ["i", "l"]: return int elif typeCode in ["c"]: return str else: raise Exception("Unrecognised type code: " + typeCode) return
7ac115f94958842c47168dc6ff9e432caac48404
636,488
def nullprep(*args, **kwrags): """NULL preperation function which always returns ``None``""" return None
a1614c5ad0c79a59ff6850007128aa31ed7c242b
163,575
def process_txt(label_path: str): """Read label & split shapes appropriately. Arguments: label_path {str} -- File path to label. Returns: tuple -- Splitted shapes: square, circle, triangle. """ # Read, strip white space & split label. with open(label_path, mode='r') as f: ...
ece587ce705a023dc7c31876fca598bf5f68a2f2
399,915
from typing import List from typing import Any from typing import Tuple def _longest_repeat_with_size(tokens: List[Any], start: int, span_len: int) -> Tuple[int, int]: """Get longest repeat start at some id with certain repeat size. For example, _longest_repeat_with_size([2,2, 3, 3,...
2d9b3322a274788383d515702b201ce9864f50e4
496,166
def get_user_list(cursor): """ Get the list of the users and their roles/permissions Parameters: ----------- cursor: Psycopg2 cursor cursor in the connection to the postgres database Returns: -------- res: List List of dictionaries with the following elements: ui...
168e08b68c2cdcc5601d31613a370f228026612b
462,149
import torch def loss_uGLAD(theta, S): """The objective function of the graphical lasso which is the loss function for the unsupervised learning of glad loss-glasso = 1/M(-log|theta| + <S, theta>) NOTE: We fix the batch size B=1 for `uGLAD` Args: theta (tensor 3D): precision matrix BxDx...
a5af2f2c189cde499f6516ca3585fd97ab0269d6
268,352
def get_images_and_fieldstrength_indices(data, source_field_strength, target_field_strength): """ extract images and indices of source/target images for the training and validation set gives back indices instead of subsets to use hdf5 datasets instead of ndarrays (to save memory) :param data: hdf5 datas...
8cf83138dbea033bc5515722f3db90940badf5ca
287,970
def drop_columns(cols): """Drop columns in a DataFrame.""" def dropper(data): return data.drop(columns=cols) return dropper
e93b1e45b9eda800aa812a41a02c78f459d65172
645,179
def get_list_as_str(list_of_objs): """ Returns the list as a string. """ return '[' + ' '.join([str(x) for x in list_of_objs]) + ']'
5b747f727d87db2ea4edd3b6aeedd27b25a7b49e
72,808
from typing import List from typing import Dict def enrich_asset_properties(properties: List, properties_to_enrich_dict: Dict) -> Dict: """ Receives list of properties of an asset, and properties to enrich, and returns a dict containing the enrichment Args: properties (List): List of properties of...
5aba396d96ad1b14f9099a4c023ce1acac67a4a7
112,004
from typing import Tuple def relative(current_module: str, reference: str) -> Tuple[str, str]: """Find relative module path.""" current_module_path = current_module.split('.') if current_module else [] *reference_path, name = reference.split('.') if current_module_path == reference_path: ret...
92d63137a94a936b66a4293adcc656cd4cbad1b7
199,253
from datetime import datetime def pretty_date(time): """ Get a datetime object or a int() Epoch timestamp and return a pretty string like 'an hour ago', 'Yesterday', '3 months ago', 'just now', etc Based on https://stackoverflow.com/a/1551394/713980 Adapted by sven1103 """ now = datet...
5b56f1bb911cac34f245258d84adbc8d927b9a49
617,989
def most_frequent(series): """Get most frequent value""" counts = series.value_counts() if not counts.empty: return counts.index[0]
aa209394cdadda042206a15f7f26c3dd94960edf
248,931
import codecs def get_constant_string(bv, addr): """ Returns the full string in memory :param bv: the BinaryView: :param addr: Address where the string is: :return string: """ str_len = 0 curr = codecs.encode(bv.read(addr, 1), "hex").decode() while (curr != "2e") and (curr != "00")...
d1fe728ad7435cd74d8d035082b629405e5b4b2a
292,804
from typing import OrderedDict import json def dump_json(obj, separators=(', ', ': '), sort_keys=False): """Dump object into a JSON string.""" if sort_keys is None: sort_keys = not isinstance(obj, OrderedDict) # Let it sort itself. return json.dumps(obj, separators=separators, sort_keys=sort_keys...
9c800ceee12cbe5b3cf4eda9530b018ecdf22dc8
81,806
def calc_invest_cost_deg(length, nb_con, nb_sub, share_lhn=0): """ Calculate investment cost into multiple deg networks Parameters ---------- length : float Total length of deg cables nb_con : int Number of buildings connected to deg (defines number of smart meters) nb_sub :...
8e168c1f024c0c31613f41d457cbf978729bdb38
278,972
def _valid_char_in_line(char: bytes, line: bytes) -> bool: """Return True if a char appears in the line and is not commented.""" comment_index = line.find(b"#") char_index = line.find(char) valid_char_in_line = char_index >= 0 and ( comment_index > char_index or comment_index < 0 ) retur...
fc9c371171d19b012b1d157b85274a9dd3c6cc13
114,949
from datetime import datetime def get_run_name(config): """Returns timestamped name for this run based on config file. Args: config (dict): Overall config dict. Returns: str: Timestamped name for this run. """ dataset_name = config["dataset"]["name"] model_name = config["mode...
32cd1f64f86360d748586f52b8720634a668427d
137,212
def unique_id(ID, IDList): """ Assigns a unique ID to each spectral target. A spectral target may appear in multiple files so unique_id assigns IDs by appending _<New number> to the spectral target ID. Parameters ---------- ID : String Spectral target ID. IDList : Dictionary...
1b0b4097eeb493414b33aa55e4409d63f90af3eb
606,883
def get_builder_image_url(benchmark, fuzzer, docker_registry): """Get the URL of the docker builder image for fuzzing the benchmark with fuzzer.""" return '{docker_registry}/builders/{fuzzer}/{benchmark}'.format( docker_registry=docker_registry, fuzzer=fuzzer, benchmark=benchmark)
ba427129c65e12c00221c9b6849f0daa68343f3b
218,858
def constructLimitsOffsets(limit, offset): """ Create a list of limit and offset pairs for partial fetching of maximum 100 apps. Arguments: limit -- the number of apps to fetch offset -- the offset from where to start fetching Returns: A list of limit,offset pairs where limit is no larger than 100 "...
8c8417d91e9eed9cca9b396783619f8f113e831b
268,667
def stringify_keys(d): # taken from https://stackoverflow.com/a/51051641 """Convert a dict's keys to strings if they are not.""" keys = list(d.keys()) for key in keys: # check inner dict if isinstance(d[key], dict): value = stringify_keys(d[key]) else: va...
5e235823af70107eb96ddde91f7175442b32efb3
673,997
import math def pure_replication(organism, population_dict, world, position_hash_table=None): """ Replace organism with two organism with similar parameters. Essentially, only differences in parameters are organism id, ancestry, age, and water / food levels. """ new_organism_list = [] # ...
5bdaa505324e55cebd907231bf189de947cc3418
464,837
import random def extract_words(text, word_count): """ Extract a list of words from a text in sequential order. :param text: source text, tokenized :param word_count: number of words to return :return: list list of words """ text_length = len(text) if word_count > text_length: ...
f84f8b4148380d6c6e29dc0742e42481dda2d11a
700,042
def size_of(rect): """Return size of list|tuple `rect` (top, left, bottom, right) as tuple (width, height)""" return (rect[3] - rect[1], rect[2] - rect[0])
07f50d974e74efca3b7985822fe3b3c84cdc2538
679,177
def create_evasion_ground_truth(user_data, evasive_spams): """Assign label 1 to evasive spams and 0 to all existing reviews; Assign labels to accounts accordingly Args: user_data: key = user_id, value = list of review tuples. user_data can contain only a subset of reviews (for example, if some of the reviews ...
15802d7b773ec4ed4445203932af9dbb6761559c
458,894
def find_item(item_to_find, items_list): """ Returns True if an item is found in the item list. :param item_to_find: item to be found :param items_list: list of items to search in :return boolean """ is_found = False for item in items_list: if item[1] == item_to_find[1]: ...
e3eb3d81eff44c6daae201222751d596d11c35ad
451,928
from pathlib import Path def genome_fasta_dir(data_dir: Path) -> Path: """Genome fasta direcotry""" return data_dir / "genome_fasta"
5ae94b3123e728d8e19ac132896fd1aa256c0d5e
90,892
def process_message_buffer(curr_message_buffer): """ Description =========== Helper function to process the communication between the master _hole_finder_multi_process and _hole_finder_worker processes. Since communication over a socket is only guaranteed to be in order, we have ...
e0793a6a70acd22070398b190a68e8718414d2ca
486,185
def createFunctionArgs(args): """ Converts args to a tuple we can pass to a function using the *args method. """ if args is None: return tuple() if isinstance(args, str): return (args,) # then it must be some kind of list, return as (a,b, ...) return tuple(args)
bb4653854d917bdec28425edb6083d29c2242a06
122,093
def readline_comment(file, symbol='#'): """Reads line from a file object, but ignores everything after the comment symbol (by default '#')""" line = file.readline() if not line: return '' result = line.partition(symbol)[0] return result if result else readline_comment(file)
bd964dfb2c9bc877e9c8ed3c9f280131468a7a10
675,189
def _get_iso_name(node, label): """Returns the ISO file name for a given node. :param node: the node for which ISO file name is to be provided. :param label: a string used as a base name for the ISO file. """ return "%s-%s.iso" % (label, node.uuid)
3d73236bfa2b8fab8af39b9a3083b540e93eb30d
24,510
def _str_strip(string): """Provide a generic strip method to pass as a callback.""" return string.strip()
24c1a4d8b9f3046a3729e1f65b6514c3cebf280f
216,566
def get_dictionary_from_flags(params, input_flags): """Generate dictionary from non-null flags. Args: params: Python dictionary of model parameters. input_flags: All the flags with non-null value of overridden model parameters. Returns: Python dict of overriding model parameters. """ if not ...
ad19134912b34dc2a5c3b38d01df5ee159cc6272
340,661
def item_sum(seq, name): """Return the sum of an iterable by attribute or key""" if seq and isinstance(seq[0], dict): return sum(i[name] for i in seq) return sum(getattr(i, name) for i in seq)
420142f365721801fc39941bce5c1a5ecd8c2ae7
224,952
def compute_profile_updates(local_profiles, remote_profiles): """ Compare a local set of profiles with a remote set. Return a list of profiles to add, and a list of profiles that have been updated. """ # Note: no profile will ever be removed, I guess we don't care new = list() updated = ...
f546f38156e845b0e589f0fcf2eab22ebc1fa697
246,330
import math def bounding_hues_from_renotation(hue, code): """ Returns for a given hue the two bounding hues from *Munsell Renotation System* data. Parameters ---------- hue : numeric *Munsell* *Colorlab* specification hue. code : numeric *Munsell* *Colorlab* specification ...
72d247c9418b1c6e51ec56e6e10f79203631ae78
675,505
from typing import Union from pathlib import Path def is_binary_file(filename: Union[str, Path]) -> bool: """ Check if file is a binary file. Args: filename (`str` or `Path`): The filename to check. Returns: `bool`: `True` if the file passed is a binary file, `False` othe...
5292802082f0b93096ea3e044305c0219a7e1a01
582,791
from datetime import datetime import pytz def utc_from_timestamp(timestamp: float) -> datetime: """Return a UTC time from a timestamp.""" return pytz.utc.localize(datetime.utcfromtimestamp(timestamp))
09d81910f23fa9d7a081d5e39857c5160c743dd2
39,375