content
stringlengths
7
1.05M
fixed_cases
stringlengths
1
1.28M
photos = Photo.objects.all() captions = [] for idx, photo in enumerate(photos): if idx > 2: break thumbnail_path = photo.thumbnail.url with open("." + thumbnail_path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) encoded_string = str(encoded_string)[2:-1] resp_captions = requests.po...
photos = Photo.objects.all() captions = [] for (idx, photo) in enumerate(photos): if idx > 2: break thumbnail_path = photo.thumbnail.url with open('.' + thumbnail_path, 'rb') as image_file: encoded_string = base64.b64encode(image_file.read()) encoded_string = str(encoded_string)[2:-1] ...
def quickSort(my_array): qshelper(my_array, 0, len(my_array) - 1) return my_array def qshelper(my_array, start, end): if start >= end: return pivot = start left = start + 1 right = end while right >= left: if my_array[left] > my_array[pivot] and my_array[right] < ...
def quick_sort(my_array): qshelper(my_array, 0, len(my_array) - 1) return my_array def qshelper(my_array, start, end): if start >= end: return pivot = start left = start + 1 right = end while right >= left: if my_array[left] > my_array[pivot] and my_array[right] < my_array[p...
#!/usr/bin/env python """ MULTPOTS Multiply potentials into a single potential newpot = multpots(pots) multiply potentials : pots is a cell of potentials potentials with empty tables are ignored if a table of type 'zero' is encountered, the result is a table of type 'zero' with table 0, and empty variables. """ def...
""" MULTPOTS Multiply potentials into a single potential newpot = multpots(pots) multiply potentials : pots is a cell of potentials potentials with empty tables are ignored if a table of type 'zero' is encountered, the result is a table of type 'zero' with table 0, and empty variables. """ def multpots(pots): new...
class Category: def __init__(self, name): self.name = name self.ledger = [] def __str__(self): l = len(self.name) n1 = 15-int(l/2) n2 = 30-(n1+l) title = "*"*n1+self.name+"*"*n2+"\n" summary = "" for item in self.ledger: a= format(item[...
class Category: def __init__(self, name): self.name = name self.ledger = [] def __str__(self): l = len(self.name) n1 = 15 - int(l / 2) n2 = 30 - (n1 + l) title = '*' * n1 + self.name + '*' * n2 + '\n' summary = '' for item in self.ledger: ...
#Max value from a list numbers = [] lenght = int(input("Enter list lenght...\n")) for i in range(lenght): numbers.append(float(input("Enter an integer or decimal number...\n"))) print("The min value is: " + str(min(numbers)))
numbers = [] lenght = int(input('Enter list lenght...\n')) for i in range(lenght): numbers.append(float(input('Enter an integer or decimal number...\n'))) print('The min value is: ' + str(min(numbers)))
#---------------------------------------------------------------------------------------------------------- # # AUTOMATICALLY GENERATED FILE TO BE USED BY W_HOTBOX # # NAME: Reconnect by Title # COLOR: #6b4930 # #---------------------------------------------------------------------------------------------------------- ...
ns = [n for n in nuke.selectedNodes() if n.knob('identifier')] for n in ns: try: n['reconnect_by_title_this'].execute() except: pass
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): # def __init__(self): # self.curr_head = None # # def isPalindrome(self, head): # """ # :type head: ListNode # ...
class Solution(object): def is_palindrome(self, head): if head is None: return True (p1, p2) = (head, head) (p3, pre) = (p1.next, p1) while p2.next is not None and p2.next.next is not None: p2 = p2.next.next pre = p1 p1 = p3 ...
class SisChkpointOpType(basestring): """ Checkpoint type Possible values: <ul> <li> "scan" - Scanning volume for fingerprints, <li> "start" - Starting a storage efficiency operation, <li> "check" - Checking for stale data in the fingerprint database, <li>...
class Sischkpointoptype(basestring): """ Checkpoint type Possible values: <ul> <li> "scan" - Scanning volume for fingerprints, <li> "start" - Starting a storage efficiency operation, <li> "check" - Checking for stale data in the fingerprint database, <li>...
l = ["Camera", "Laptop", "Phone", "ipad", "Hard Disk", "Nvidia Graphic 3080 card"] # sentence = "~~".join(l) # sentence = "==".join(l) sentence = "\n".join(l) print(sentence) print(type(sentence))
l = ['Camera', 'Laptop', 'Phone', 'ipad', 'Hard Disk', 'Nvidia Graphic 3080 card'] sentence = '\n'.join(l) print(sentence) print(type(sentence))
# Linked List, Two Pointers # Given a singly linked list, determine if it is a palindrome. # # Example 1: # # Input: 1->2 # Output: false # Example 2: # # Input: 1->2->2->1 # Output: true # Follow up: # Could you do it in O(n) time and O(1) space? # Definition for singly-linked list. # class ListNode(object): # d...
class Solution(object): def is_palindrome(self, head): """ :type head: ListNode :rtype: bool """ if head is None or head.next is None: return True (slow, fast) = (head, head) while fast != None and fast.next != None: slow = slow.next ...
# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, s...
class Schemamode: backend = 'BE' frontend = 'FE' def make_type(typename, required): if required: return [typename] else: return ['null', typename] def add_field(schema, name, field_type): schema['fields'].append({'name': name, 'type': field_type}) def add_string(schema, name, requ...
""" Module to handle universal/general constants used across files. """ ################################################################################ # Constants # ################################################################################ # GENERAL CONSTANTS: VERY_SMALL_NUMBER = 1e-31 INF = 1e20 _PAD_TOKEN...
""" Module to handle universal/general constants used across files. """ very_small_number = 1e-31 inf = 1e+20 _pad_token = '#pad#' _unk_token = '<unk>' _sos_token = '<s>' _eos_token = '</s>' _config_file = 'config.json' _saved_weights_file = 'params.saved' _prediction_file = 'test_pred.txt' _reference_file = 'test_ref....
def test_catch_server__get(testdir): testdir.makepyfile( """ import urllib.request def test_get(catch_server): url = "http://{cs.host}:{cs.port}/get_it".format(cs=catch_server) request = urllib.request.Request(url, method="GET") with urllib.request.urlop...
def test_catch_server__get(testdir): testdir.makepyfile('\n import urllib.request\n\n def test_get(catch_server):\n url = "http://{cs.host}:{cs.port}/get_it".format(cs=catch_server)\n request = urllib.request.Request(url, method="GET")\n\n with urllib.request.urlopen(r...
# Roll the Dice # # November 17, 2018 # By Robin Nash n = int(input()) m = int(input()) if n > 10: n = 9 if m > 10: m = 9 ways = 0 for n in range (1,n+1): for m in range(1,m+1): if n + m == 10: ways+=1 if ways == 1: print("There is 1 way to get the sum 10.") e...
n = int(input()) m = int(input()) if n > 10: n = 9 if m > 10: m = 9 ways = 0 for n in range(1, n + 1): for m in range(1, m + 1): if n + m == 10: ways += 1 if ways == 1: print('There is 1 way to get the sum 10.') else: print('There are', ways, 'ways to get the sum 10.')
Carros = ['HRV', 'Polo', 'Jetta', 'Palio', 'Fusca'] itCarros = iter(Carros) while itCarros: try: print(next(itCarros)) except StopIteration: print('Fim da Lista.') break
carros = ['HRV', 'Polo', 'Jetta', 'Palio', 'Fusca'] it_carros = iter(Carros) while itCarros: try: print(next(itCarros)) except StopIteration: print('Fim da Lista.') break
def default_colors(n): n = max(n, 8) clist = ["#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e", "#e6ab02", "#a6761d", "#666666"] return clist[:n]
def default_colors(n): n = max(n, 8) clist = ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'] return clist[:n]
def nth_fibonacci_using_recursion(n): if n < 0: raise ValueError("n should be a positive number or zero") else: if n == 1: return 0 elif n == 2: return 1 else: return nth_fibonacci_using_recursion(n - 2) + nth_fibonacci_using_recursion(n - 1) ...
def nth_fibonacci_using_recursion(n): if n < 0: raise value_error('n should be a positive number or zero') elif n == 1: return 0 elif n == 2: return 1 else: return nth_fibonacci_using_recursion(n - 2) + nth_fibonacci_using_recursion(n - 1) def nth_fibonacci_using_iterati...
class OpenInterest: def __init__(self): self.symbol = "" self.openInterest = 0.0 @staticmethod def json_parse(json_data): result = OpenInterest() result.symbol = json_data.get_string("symbol") result.openInterest = json_data.get_float("openInterest") ...
class Openinterest: def __init__(self): self.symbol = '' self.openInterest = 0.0 @staticmethod def json_parse(json_data): result = open_interest() result.symbol = json_data.get_string('symbol') result.openInterest = json_data.get_float('openInterest') return...
with open("input.txt") as input_file: time = int(input_file.readline().strip()) busses = input_file.readline().strip().split(",") def departures(bus): multiplier = 0 while True: multiplier += 1 yield multiplier * bus def next_after(bus, time): for departure in departures(bus): ...
with open('input.txt') as input_file: time = int(input_file.readline().strip()) busses = input_file.readline().strip().split(',') def departures(bus): multiplier = 0 while True: multiplier += 1 yield (multiplier * bus) def next_after(bus, time): for departure in departures(bus): ...
# -*- coding: utf-8 -*- maior = -1 index_maior = -1 for i in range(1, 101): n = int(input()) if n > maior: maior = n index_maior = i print(maior) print(index_maior)
maior = -1 index_maior = -1 for i in range(1, 101): n = int(input()) if n > maior: maior = n index_maior = i print(maior) print(index_maior)
# This sample tests a particularly difficult set of dependent # assignments that involve tuple packing and unpacking. # pyright: strict v1 = "" v3 = "" v2, _ = v1, v3 v4 = v2 for _ in range(1): v1 = v4 v2, v3 = v1, ""
v1 = '' v3 = '' (v2, _) = (v1, v3) v4 = v2 for _ in range(1): v1 = v4 (v2, v3) = (v1, '')
class DNABattleCell: COMPONENT_CODE = 21 def __init__(self, width, height, pos): self.width = width self.height = height self.pos = pos def setWidth(self, width): self.width = width def setHeight(self, height): self.height = height def setWidthHeight(self,...
class Dnabattlecell: component_code = 21 def __init__(self, width, height, pos): self.width = width self.height = height self.pos = pos def set_width(self, width): self.width = width def set_height(self, height): self.height = height def set_width_height(s...
def median(a): a = sorted(a) list_length = len(a) num = list_length//2 if list_length % 2 == 0: median_num = (a[num] + a[num + 1])/2 else: median_num = a[num] return median_num
def median(a): a = sorted(a) list_length = len(a) num = list_length // 2 if list_length % 2 == 0: median_num = (a[num] + a[num + 1]) / 2 else: median_num = a[num] return median_num
class DeviceGroup: def __init__(self, name): self.name = name self.devices = [] def addDevice(self, newDevice): self.devices.append(newDevice) # Just thinking through how I want the program to work. # A diskgroup should be initialized once every time the service is started. ...
class Devicegroup: def __init__(self, name): self.name = name self.devices = [] def add_device(self, newDevice): self.devices.append(newDevice)
#!/usr/bin/env python3 def read_text(): """Reads a line of text, stripping whitespace.""" return input().strip() def distance(s, t): """Wagner-Fischer algorithm""" if len(s) < len(t): s, t = t, s pre = [None] * (len(t) + 1) cur = list(range(len(pre))) for i, sc in enumerate(s, ...
def read_text(): """Reads a line of text, stripping whitespace.""" return input().strip() def distance(s, t): """Wagner-Fischer algorithm""" if len(s) < len(t): (s, t) = (t, s) pre = [None] * (len(t) + 1) cur = list(range(len(pre))) for (i, sc) in enumerate(s, 1): (pre, cur)...
# -*- coding: utf-8 -*- """ 665. Non-decreasing Array Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2). Constraints: 1 <=...
""" 665. Non-decreasing Array Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2). Constraints: 1 <= n <= 10 ^ 4 - 10 ^ 5 <=...
# -*- coding: utf-8 -*- USER_ROLE = { 'USER': 0, 'MODERATOR': 1, 'ADMINISTRATOR': 2, }
user_role = {'USER': 0, 'MODERATOR': 1, 'ADMINISTRATOR': 2}
a = 1 print("a_module: Hi from my_package/" + __name__ + ".py!") if __name__ == "__main__": print("a_module: I was invoked from a script.") else: print("a_module: I was invoked from a Pyton module (probably using 'import').") print("a_module: My name is =", __name__)
a = 1 print('a_module: Hi from my_package/' + __name__ + '.py!') if __name__ == '__main__': print('a_module: I was invoked from a script.') else: print("a_module: I was invoked from a Pyton module (probably using 'import').") print('a_module: My name is =', __name__)
# # PySNMP MIB module ZYXEL-MES2110-MIB (http://snmplabs.com/pysmi) # ASN.1 source file:///Users/davwang4/Dev/mibs.snmplabs.com/asn1/ZYXEL-MES2110-MIB # Produced by pysmi-0.3.4 at Wed May 1 15:50:49 2019 # On host DAVWANG4-M-1475 platform Darwin version 18.5.0 by user davwang4 # Using Python version 3.7.3 (default, Ma...
(object_identifier, octet_string, integer) = mibBuilder.importSymbols('ASN1', 'ObjectIdentifier', 'OctetString', 'Integer') (named_values,) = mibBuilder.importSymbols('ASN1-ENUMERATION', 'NamedValues') (single_value_constraint, constraints_intersection, value_range_constraint, value_size_constraint, constraints_union) ...
userNum = int(input("Input a number: ")) out = "" numeralArr = [(1000, "M"), (500, "D"), (100, "C"), (50, "L"), (10, "X"), (5, "V"), (1, "I"), (0, ""), (0, "")] def convert(num, nums, iters, halfs): global out if n...
user_num = int(input('Input a number: ')) out = '' numeral_arr = [(1000, 'M'), (500, 'D'), (100, 'C'), (50, 'L'), (10, 'X'), (5, 'V'), (1, 'I'), (0, ''), (0, '')] def convert(num, nums, iters, halfs): global out if num >= nums[0] - iters[0]: out += iters[1] + nums[1] num -= nums[0] - iters[0] ...
d = {} palavra = 'Felipe Schmaedecke' for l in palavra: if l in d: d[l] = d[l] + 1 else: d[l] = 1 print(d)
d = {} palavra = 'Felipe Schmaedecke' for l in palavra: if l in d: d[l] = d[l] + 1 else: d[l] = 1 print(d)
class ECA: def __init__(self, id): self.id = bin(id)[2:].zfill(8) self.dict = {} for i in range(8): self.dict[bin(7 - i)[2:].zfill(3)] = self.id[i] self.array = [0 for x in range(199)] self.array[99] = 1 def step(self): arr = [0 for x in range(len(s...
class Eca: def __init__(self, id): self.id = bin(id)[2:].zfill(8) self.dict = {} for i in range(8): self.dict[bin(7 - i)[2:].zfill(3)] = self.id[i] self.array = [0 for x in range(199)] self.array[99] = 1 def step(self): arr = [0 for x in range(len(se...
expected_output = { "service_instance": { 501: { "interfaces": { "TenGigabitEthernet0/3/0": {"state": "Up", "type": "Static"}, "TenGigabitEthernet0/1/0": {"state": "Up", "type": "Static"}, } }, 502: { "interfaces": {"TenGiga...
expected_output = {'service_instance': {501: {'interfaces': {'TenGigabitEthernet0/3/0': {'state': 'Up', 'type': 'Static'}, 'TenGigabitEthernet0/1/0': {'state': 'Up', 'type': 'Static'}}}, 502: {'interfaces': {'TenGigabitEthernet0/3/0': {'state': 'Up', 'type': 'Static'}}}}}
class KNNClassifier(object): def __init__(self, k=3, distance=None): self.k = k self.distance = distance def fit(self, x, y): pass def predict(self, x): pass def __decision_function(self): pass
class Knnclassifier(object): def __init__(self, k=3, distance=None): self.k = k self.distance = distance def fit(self, x, y): pass def predict(self, x): pass def __decision_function(self): pass
''' Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) ''' # Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # s...
""" Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) """ class Solution(object): def swap_pairs(self, head): if not head or not head.next: return hea...
with open("Prob03.in.txt") as f: content = f.readlines() content = [x.strip() for x in content] nola = content.pop(0) for x in content: x = x.strip(" ") x = x.split() add = int(x[0]) + int(x[1]) multi = int(x[0]) * int(x[1]) print( str(add) + " " + str(multi))
with open('Prob03.in.txt') as f: content = f.readlines() content = [x.strip() for x in content] nola = content.pop(0) for x in content: x = x.strip(' ') x = x.split() add = int(x[0]) + int(x[1]) multi = int(x[0]) * int(x[1]) print(str(add) + ' ' + str(multi))
## Script (Python) "getFotoCapa" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title=Retorna um nome de arquivo para ser usado como foto da capa padrao = [ 'capa01.jpg','capa02.jpg','capa03.jpg','capa04.jpg','capa05.jpg', \ ...
padrao = ['capa01.jpg', 'capa02.jpg', 'capa03.jpg', 'capa04.jpg', 'capa05.jpg', 'capa06.jpg', 'capa07.jpg'] ultimo = context.portal_catalog.searchResults(portal_type='Programa', sort_on='getData', sort_order='reverse', review_state='published')[0] imagem = ultimo.getImagem if not imagem: imagem = context.portal_url...
# -*- coding: utf-8 -*- # Define your item pipelines here # # Don't forget to add your pipeline to the ITEM_PIPELINES setting # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html class DoubanPipeline(object): # def __init__(self, server, port): # pass # @classmethod # def from_craw...
class Doubanpipeline(object): def process_item(self, item, spider): return item
# # PySNMP MIB module CISCO-LAG-CAPABILITY (http://snmplabs.com/pysmi) # ASN.1 source file:///Users/davwang4/Dev/mibs.snmplabs.com/asn1/CISCO-LAG-CAPABILITY # Produced by pysmi-0.3.4 at Mon Apr 29 17:47:12 2019 # On host DAVWANG4-M-1475 platform Darwin version 18.5.0 by user davwang4 # Using Python version 3.7.3 (defau...
(integer, octet_string, object_identifier) = mibBuilder.importSymbols('ASN1', 'Integer', 'OctetString', 'ObjectIdentifier') (named_values,) = mibBuilder.importSymbols('ASN1-ENUMERATION', 'NamedValues') (value_size_constraint, value_range_constraint, single_value_constraint, constraints_union, constraints_intersection) ...
def test_epl_single_year_mtl(style_checker): """Style check test against epl_single_year.mtl """ style_checker.set_year(2017) p = style_checker.run_style_checker('--config=module_config.yaml', 'whatever', 'epl_single_year.mtl') style_checker.assertEqual(p.stat...
def test_epl_single_year_mtl(style_checker): """Style check test against epl_single_year.mtl """ style_checker.set_year(2017) p = style_checker.run_style_checker('--config=module_config.yaml', 'whatever', 'epl_single_year.mtl') style_checker.assertEqual(p.status, 0, p.image) style_checker.assert...
# -*- coding: utf-8 -*- """ Created on Wed Oct 14 07:44:37 2020 @author: ucobiz """ values = [] # initialize the list to be empty userVal = 1 # give our loop variable a value while userVal != 0: userVal = int(input("Enter a number, 0 to stop: ")) if userVal != 0: # only append if it's v...
""" Created on Wed Oct 14 07:44:37 2020 @author: ucobiz """ values = [] user_val = 1 while userVal != 0: user_val = int(input('Enter a number, 0 to stop: ')) if userVal != 0: values.append(userVal) print('Stopped!') print(values)
mylist = ["banana", "apple", "pineapple"] print(mylist) item = mylist[2] print(item) if "banana" in mylist: print("yes") else: print("no") mylist.append("lemon") print(mylist) mylist.insert(2, "grapes") print(mylist) # /item = [0] * 5 # print(item)
mylist = ['banana', 'apple', 'pineapple'] print(mylist) item = mylist[2] print(item) if 'banana' in mylist: print('yes') else: print('no') mylist.append('lemon') print(mylist) mylist.insert(2, 'grapes') print(mylist)
# These functions deal with displaying information in CLI ## Check Payment Display def display_lessons(lessons): print('displaying lesson payment info') unpaid_lessons = [] paid_lessons = [] for lesson in lessons: if lesson['paid'] == 'n': unpaid_lessons.append(lesson) elif...
def display_lessons(lessons): print('displaying lesson payment info') unpaid_lessons = [] paid_lessons = [] for lesson in lessons: if lesson['paid'] == 'n': unpaid_lessons.append(lesson) elif lesson['paid'] == 'y': paid_lessons.append(lesson) for lesson in unp...
city = input("Enter city name = ") sales = int(input("Enter sales volume = ")) cities = ["Sofia", "Varna", "Plovdiv"] index = 4 #Discounts by cities if 0 <= sales and sales <= 500: comision = [0.05,0.045,0.055] elif 500 < sales and sales <= 1000: comision = [0.07,0.075,0.08] elif 1000 < sales and sales <= 1000...
city = input('Enter city name = ') sales = int(input('Enter sales volume = ')) cities = ['Sofia', 'Varna', 'Plovdiv'] index = 4 if 0 <= sales and sales <= 500: comision = [0.05, 0.045, 0.055] elif 500 < sales and sales <= 1000: comision = [0.07, 0.075, 0.08] elif 1000 < sales and sales <= 10001: comision = ...
#! /usr/bin/python3 # -*- coding: utf-8 -*-S def crypt(line: str) -> str: result = str() for symbol in line: result += chr(ord(symbol) + 1) return result print(crypt(input()))
def crypt(line: str) -> str: result = str() for symbol in line: result += chr(ord(symbol) + 1) return result print(crypt(input()))
class Solution: # not my soln but its very cool def threeSum(self, nums: List[int]) -> List[List[int]]: triplets = set() neg, pos, zeros = [], [], 0 for num in nums: if num > 0: pos.append(num) elif num < 0: neg.append(num) ...
class Solution: def three_sum(self, nums: List[int]) -> List[List[int]]: triplets = set() (neg, pos, zeros) = ([], [], 0) for num in nums: if num > 0: pos.append(num) elif num < 0: neg.append(num) else: zero...
# -*- coding: utf-8 -*- """ Created on Mon Jan 4 09:38:16 2021 @author: gregoryvanbeek """ #%%INPUT flag = 1040 verbose=True #%% def samflags(flag=0, verbose=True): """This script converts a decimal flag to binary and get the corresponding properties according to the sam-flag standard. The code is based on...
""" Created on Mon Jan 4 09:38:16 2021 @author: gregoryvanbeek """ flag = 1040 verbose = True def samflags(flag=0, verbose=True): """This script converts a decimal flag to binary and get the corresponding properties according to the sam-flag standard. The code is based on the explanation given here https://d...
# -*- coding: utf-8 -*- # # Copyright 2016 Continuum Analytics, Inc. # May be copied and distributed freely only as part of an Anaconda or # Miniconda installation. # """ Custom errors on Anaconda Navigator. """ class AnacondaNavigatorException(Exception): pass
""" Custom errors on Anaconda Navigator. """ class Anacondanavigatorexception(Exception): pass
def change_return(amount,currency): currency.sort(reverse = True) counter = 0 amount_counter = [0]*len(currency) while amount> 0: amount_counter[counter] = int(amount/currency[counter]) amount -= amount_counter[counter]*currency[counter] counter += 1 return [(currency[i],amou...
def change_return(amount, currency): currency.sort(reverse=True) counter = 0 amount_counter = [0] * len(currency) while amount > 0: amount_counter[counter] = int(amount / currency[counter]) amount -= amount_counter[counter] * currency[counter] counter += 1 return [(currency[i...
# helpers.py, useful helper functions for wikipedia analysis # We want to represent known symbols (starting with //) as words, the rest characters def extract_tokens(tex): '''walk through a LaTeX string, and grab chunks that correspond with known identifiers, meaning anything that starts with \ and ends wit...
def extract_tokens(tex): """walk through a LaTeX string, and grab chunks that correspond with known identifiers, meaning anything that starts with \\ and ends with one or more whitespaces, a bracket, a ^ or underscore. """ regexp = '\\\\(.*?)(\\w+|\\{|\\(|\\_|\\^)' tokens = [] while re...
# -*- coding: utf-8 -*- # 0xCCCCCCCC # Like Q153 but with possible duplicates. def find_min(nums): """ :type nums: List[int] :rtype: int """ l, r = 0, len(nums) - 1 while l < r and nums[l] >= nums[r]: m = (l + r) // 2 if nums[m] > nums[r]: l = m + 1 elif num...
def find_min(nums): """ :type nums: List[int] :rtype: int """ (l, r) = (0, len(nums) - 1) while l < r and nums[l] >= nums[r]: m = (l + r) // 2 if nums[m] > nums[r]: l = m + 1 elif nums[m] < nums[r]: r = m elif nums[m] < nums[l]: ...
def seed_everything(seed=2020): random.seed(seed) os.environ['PYTHONHASHSEED'] = str(seed) np.random.seed(seed) tf.random.set_seed(seed) seed_everything(42)
def seed_everything(seed=2020): random.seed(seed) os.environ['PYTHONHASHSEED'] = str(seed) np.random.seed(seed) tf.random.set_seed(seed) seed_everything(42)
"""Tabler.""" __title__ = "enigma" __description__ = "Enigma emulator" __url__ = "" __version__ = "0.1" __author__ = "Luke Shiner" __author_email__ = "luke@lukeshiner.com" __license__ = "MIT" __copyright__ = "Copyright 2019 Luke Shiner"
"""Tabler.""" __title__ = 'enigma' __description__ = 'Enigma emulator' __url__ = '' __version__ = '0.1' __author__ = 'Luke Shiner' __author_email__ = 'luke@lukeshiner.com' __license__ = 'MIT' __copyright__ = 'Copyright 2019 Luke Shiner'
class Solution: def XXX(self, root: TreeNode) -> int: if not root: return 0 self.min_depth = float('inf') def dfs(root, depth): if not root: return if not root.left and not root.right: self.min_depth = min(self.min_depth, d...
class Solution: def xxx(self, root: TreeNode) -> int: if not root: return 0 self.min_depth = float('inf') def dfs(root, depth): if not root: return if not root.left and (not root.right): self.min_depth = min(self.min_depth...
#!/usr/bin/env python3 # Find the middle element in the list. # Create a function called middle_element that has one parameter named lst. # If there are an odd number of elements in lst, the function # should return the middle element. # If there are an even number of elements, the function should # return the average...
def middle_element(lst): if len(lst) % 2 == 0: sum = lst[int(len(lst) / 2)] + lst[int(len(lst) / 2) - 1] return sum / 2 else: return lst[int(len(lst) / 2)] print(middle_element([5, 2, -10, -4, 4, 5]))
INPUT = """1919 2959 82 507 3219 239 3494 1440 3107 259 3544 683 207 562 276 2963 587 878 229 2465 2575 1367 2017 154 152 157 2420 2480 138 2512 2605 876 744 6916 1853 1044 2831 4797 213 4874 187 6051 6086 7768 5571 6203 247 285 1210 1207 1130 116 1141 563 1056 155 227 1085 697 735 192 1236 1065 156 682 883 187 307...
input = '1919\t2959\t82\t507\t3219\t239\t3494\t1440\t3107\t259\t3544\t683\t207\t562\t276\t2963\n587\t878\t229\t2465\t2575\t1367\t2017\t154\t152\t157\t2420\t2480\t138\t2512\t2605\t876\n744\t6916\t1853\t1044\t2831\t4797\t213\t4874\t187\t6051\t6086\t7768\t5571\t6203\t247\t285\n1210\t1207\t1130\t116\t1141\t563\t1056\t155\t...
class Microstate(): def __init__(self): self.index = None self.label = None self.weight = 0.0 self.probability = 0.0 self.basin = None self.coordinates = None self.color = None self.size = None
class Microstate: def __init__(self): self.index = None self.label = None self.weight = 0.0 self.probability = 0.0 self.basin = None self.coordinates = None self.color = None self.size = None
intraband_incharge = { "WEIMIN": None, "EBREAK": None, "DEPER": None, "TIME": None, }
intraband_incharge = {'WEIMIN': None, 'EBREAK': None, 'DEPER': None, 'TIME': None}
program_name = 'giraf' program_desc = 'A command line utility to access imgur.com.'
program_name = 'giraf' program_desc = 'A command line utility to access imgur.com.'
def profile_likelihood_maximization(U, n_elbows, threshold): """ Inputs U - An ordered or unordered list of eigenvalues n - The number of elbows to return Return elbows - A numpy array containing elbows """ if type(U) == list: # cast to array for functionality later ...
def profile_likelihood_maximization(U, n_elbows, threshold): """ Inputs U - An ordered or unordered list of eigenvalues n - The number of elbows to return Return elbows - A numpy array containing elbows """ if type(U) == list: u = np.array(U) if type(U) is not np...