Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
An array is **circularly sorted** if the elements are sorted in ascending order, but displaced, or rotated, by any number of steps. Complete the function/method that determines if the given array of integers is circularly sorted. ## Examples These arrays are circularly sorted (`true`): ``` [2, 3, 4, 5, 0, 1] --> [0, 1] + [2, 3, 4, 5] [4, 5, 6, 9, 1] --> [1] + [4, 5, 6, 9] [10, 11, 6, 7, 9] --> [6, 7, 9] + [10, 11] [1, 2, 3, 4, 5] --> [1, 2, 3, 4, 5] [5, 7, 43, 987, -9, 0] --> [-9, 0] + [5, 7, 43, 987] [1, 2, 3, 4, 1] --> [1] + [1, 2, 3, 4] ``` While these are not (`false`): ``` [4, 1, 2, 5] [8, 7, 6, 5, 4, 3] [6, 7, 4, 8] [7, 6, 5, 4, 3, 2, 1] ```
def circularly_sorted(arr): smallest = arr.index(min(arr)) if arr[smallest:] + arr[:smallest] == sorted(arr): return True else: return False
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
remove=lambda s:' '.join(r for r,_ in __import__('re').findall(r'((!*)\w+\2)',s))
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def rm(word): left = len(re.search('^!*', word).group()) right = len(re.search('!*$', word).group()) ex = '!' * min(left, right) return ex + word.strip('!') + ex def remove(s): return ' '.join(map(rm, s.split()))
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(s): return ' '.join(m[0] for m in re.findall(r'((!*)\w+\2)', s))
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(stg): return " ".join(re.sub(r"(!*)([^!]+)(!*)", equalize, word) for word in stg.split()) def equalize(match): before, word, after = match.groups() shortest = min(before, after, key=len) return f"{shortest}{word}{shortest}"
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(stg): words = stg.split(" ") for i, group in enumerate(words): b, w, a = re.search(r"(!*)([^!]+)(!*)", group).groups() s = min(a, b, key=len) words[i] = f"{s}{w}{s}" return " ".join(words)
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(s): li = [] for i in s.split(): start = re.search("^!+", i) end = re.search(r"!+$", i) i = re.sub(r"^!+", "", re.sub(r"!+$", "", i)) m = min([len(start.group()) if start else 0, len(end.group()) if end else 0]) li.append(('!' * m) + i + ('!' * m)) return " ".join(li)
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(s): return re.sub(r'(!*)([^! ]+)(!*)', repl, s) def repl(m): s = '!' * min(map(len,(m[1],m[3]))) return f'{s}{ m[2] }{s}'
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
import re def remove(s): return re.sub(r'!*?((!*)\w+\2)!*',r'\1',s)
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
def remove(s): tmp = s.split(" ") for i,x in enumerate(tmp): before = 0 after = 0 while x[0] == "!": before += 1 x = x[1:] while x[-1] == "!": after += 1 x = x[:-1] count = min(before,after) bangs = "!" * count tmp[i] = bangs + x + bangs return " ".join(tmp)
# Description: Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides. ### Notes: * Words are separated with spaces * Each word will include at least 1 letter * There will be no exclamation marks in the middle of a word ___ ## Examples ``` remove("Hi!") === "Hi" remove("!Hi! Hi!") === "!Hi! Hi" remove("!!Hi! !Hi!!") === "!Hi! !Hi!" remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!" ```
def f(w): l,r = 0, 0 word = '' length = len(w) n = 0 while n!=length: if w[n] == '!': if not word: l += 1 else: r += 1 elif w[n].isalpha(): word += w[n] n += 1 return l,r, word def remove(s): l = [] for x in s.split(): a, b, word = f(x) size = min(a,b) l.append(f"{'!'*size}{word}{'!'*size}") return ' '.join(l)
Implement a function which multiplies two numbers.
def multiply(x, y): return x * y
Implement a function which multiplies two numbers.
multiply = lambda x, y: x * y
Implement a function which multiplies two numbers.
def multiply(a,b): return a * b
Implement a function which multiplies two numbers.
from operator import mul as multiply
Implement a function which multiplies two numbers.
def multiply(is_this, a_joke): return is_this*a_joke
Implement a function which multiplies two numbers.
multiply = lambda a,b: a*b
Implement a function which multiplies two numbers.
def multiply(term_one, term_two): return term_one * term_two
Implement a function which multiplies two numbers.
def multiply(a, b): product = a * b return product
Implement a function which multiplies two numbers.
def multiply(n1, n2): return n1*n2
Implement a function which multiplies two numbers.
__import__('inspect').isfunction, multiply = __import__('inspect').isbuiltin, __import__('operator').mul
Implement a function which multiplies two numbers.
def multiply(x, y): if y == 1: return x else: return x + multiply(x, y-1)
Implement a function which multiplies two numbers.
from operator import mul def multiply(*args): return mul(*args)
Implement a function which multiplies two numbers.
def multiply(a, b): mv = 0 for c in range(b): mv = sumVal(mv, a) return mv def sumVal(a, b): for c in range(b): a = add1(a) return a def add1(a): out = '' binval = dec2bin(a) carry = 0 convert = True while len(binval) > 0: if not convert: out = binval[-1] + out else: if carry == 1: if binval[-1] == '0': convert = False carry = 0 out = '1' + out else: out = '0' + out else: if binval[-1] == '0': out = '1' + out convert = False else: out = '0' + out carry = 1 binval = binval[:-1] if carry == 1: out = '1' + out return bin2dec(out) def dec2bin(a): if a == 0: return '0' out = '' while a > 0: out = str(a%2) + out a = a //2 return out def bin2dec(a): out = 0 while len(a) > 0: out *= 2 out += int(a[0]) a = a[1:] return out
Implement a function which multiplies two numbers.
def multiply(a,b): return (a).__mul__(b)
Implement a function which multiplies two numbers.
def multiply(a,b): return a if b == 1 else a + multiply(a, b ^ 1) if b & 1 else multiply(a + a, b >> 1) if b else 0
Implement a function which multiplies two numbers.
multiply = int.__mul__
Implement a function which multiplies two numbers.
def multiply(*_): return _[0]*_[1]
Implement a function which multiplies two numbers.
from operator import mul #as multiply multiply = lambda *args, **kwargs: mul(*args, **kwargs)
Implement a function which multiplies two numbers.
def multiply(a,b): return 0 if b == 0 else a if b == 1 else a + multiply(a, b ^ 1) if b & 1 else multiply(a + a, b >> 1)
Implement a function which multiplies two numbers.
import operator as op multiply = op.mul
Implement a function which multiplies two numbers.
#your code hered def multiply(a,b): return a*b
Implement a function which multiplies two numbers.
def multiply(a, b): return round(a * b)
Implement a function which multiplies two numbers.
def multiply(n,s): return n*s
Implement a function which multiplies two numbers.
def multiply(arg_int_a, arg_int_b): return arg_int_a * arg_int_b
Implement a function which multiplies two numbers.
def multiply(x, y): m = x * y return m
Implement a function which multiplies two numbers.
#your code here def multiply (num1, num2): answer = num1 * num2 return answer
Implement a function which multiplies two numbers.
from operator import mul multiply=mul
Implement a function which multiplies two numbers.
a = 1 b = 4 def multiply(a, b): return a * b
Implement a function which multiplies two numbers.
def multiply(number1, number2): x = number1 * number2 return x
Implement a function which multiplies two numbers.
from operator import mul multiply = lambda a,b: mul(a, b)
Implement a function which multiplies two numbers.
import operator multiply = operator.mul
Implement a function which multiplies two numbers.
def multiply(*args): z = 1 for num in args: z *= num return z
Implement a function which multiplies two numbers.
def multiply(szam1,szam2): return szam1*szam2 multiply(2,3)
Implement a function which multiplies two numbers.
def multiply(u,y): return u*y
Implement a function which multiplies two numbers.
def multiply(tbilisi,telavi): return(tbilisi*telavi)
Implement a function which multiplies two numbers.
def multiply(a, b): m = a * b return m
Implement a function which multiplies two numbers.
def multiply(number_1, number_2): return number_1 * number_2
Implement a function which multiplies two numbers.
def multiply(*args): p = 1 for a in args: p *= a return p
Implement a function which multiplies two numbers.
def multiply(x, y): if x * y: return x * y print((multiply(2, 4)))
Implement a function which multiplies two numbers.
multiply = lambda a, b : a * b #just learned to use lambda :D
Implement a function which multiplies two numbers.
#your code here def multiply(a, b): return a*b a =2 b =3 print(multiply(a, b))
Implement a function which multiplies two numbers.
def multiply(x,v): return x*v
Implement a function which multiplies two numbers.
def multiply(a, b): return a * b print(multiply(7,9))
Implement a function which multiplies two numbers.
def multiply(n, m): return n * m print((multiply(2,5)))
Implement a function which multiplies two numbers.
def multiply(num1,num2): a = num1 * num2 return a
Implement a function which multiplies two numbers.
def multiply(a,b): print(a,b) return a*b
Implement a function which multiplies two numbers.
def multiply(x:int, y:int) -> int: return x*y
Implement a function which multiplies two numbers.
def multiply(numbers, argumentol): results = numbers * argumentol return results
Implement a function which multiplies two numbers.
# from operator import mul as multiply def multiply(a, b) -> int: return a*b
Implement a function which multiplies two numbers.
def multiply(a, b) -> int: return a * b
Implement a function which multiplies two numbers.
def multiply(a, b): return a * b multiply(2, 2)
Implement a function which multiplies two numbers.
def multiply(n, b): a = n * b return a
Implement a function which multiplies two numbers.
def multiply(a: int, b: int) -> int: return a*b
Implement a function which multiplies two numbers.
def multiply(a,b): a_start = a for s in range(0, b-1): a += a_start return a
Implement a function which multiplies two numbers.
def multiply(x,y): c = x*y return c
Implement a function which multiplies two numbers.
def multiply(first_number, second_number): return first_number * second_number #your code here
Implement a function which multiplies two numbers.
multiply = lambda n, m: n * m
Implement a function which multiplies two numbers.
def multiply(*args): c = 1 for i in args: c = c * i print(str(c)) return c multiply(2,4,3)
Implement a function which multiplies two numbers.
from operator import mul def multiply(*args: int) -> int: return mul(*args)
Implement a function which multiplies two numbers.
def multiply(q,w): return q*w#your code here
Implement a function which multiplies two numbers.
def multiply(a,s): return a * s
Implement a function which multiplies two numbers.
def multiply(v1,v2): return v1 * v2
Implement a function which multiplies two numbers.
#your code here def multiply(a,b): print(a*b) return a*b
Implement a function which multiplies two numbers.
def multiply(a,b): print(a) print(b) return a*b print(multiply(3,4))
Implement a function which multiplies two numbers.
def multiply(value1, value2): return (value1 * value2)#your code here
Implement a function which multiplies two numbers.
def multiply(a,b): return a * b #Completed by Ammar on 13/8/2019 at 04:00PM.
Implement a function which multiplies two numbers.
def multiply(a,b): return a*b #I solved this Kata on 7/27/2019 08:28 PM...#Hussam'sCodingDiary
Implement a function which multiplies two numbers.
#your code here def multiply (nr1, nr2): return nr1 * nr2
Implement a function which multiplies two numbers.
multiply = lambda x, y: x * y """ def multiply(a,b): if a is int or a is float and b is int or b is float: return a * b else: raise TypeError("NaN") """
Implement a function which multiplies two numbers.
multiply = lambda *a : ( (lambda ft, op: ft.reduce(op.mul, a)) (*[__import__(x) for x in ['functools', 'operator']]))
Implement a function which multiplies two numbers.
def multiply(a, b): """Performs a multiplciaton, with numbers a and b.""" # multiplication cal = float(a) * float(b) return cal
Implement a function which multiplies two numbers.
multiply = lambda n,m: m*n
Implement a function which multiplies two numbers.
def multiply(thing1, thing2): return thing1 * thing2
Implement a function which multiplies two numbers.
def multiply (num1, num2): return num1 * num2 print(multiply(3, 4))
Implement a function which multiplies two numbers.
def multiply(a,b): return a*b """multiply two arguments , and return the multiplication of the two arguments"""
Implement a function which multiplies two numbers.
def multiply (n, n_1): return n * n_1
Implement a function which multiplies two numbers.
multiply = lambda a, b: b * a
Implement a function which multiplies two numbers.
multiply = lambda n1, n2: n1 * n2
Implement a function which multiplies two numbers.
#your code here def multiply(a=0, b=0): return a*b
Implement a function which multiplies two numbers.
def multiply(n, n_2): return n*n_2
Implement a function which multiplies two numbers.
def multiply(a,b): return sum([a for i in range(b)])
Implement a function which multiplies two numbers.
def multiply(second,first): return second*first
Implement a function which multiplies two numbers.
def multiply (numb1,numb2): return numb1 * numb2
Implement a function which multiplies two numbers.
def multiply(a, b): res = a * b return res
Implement a function which multiplies two numbers.
multiply = lambda i,j: i * j
Implement a function which multiplies two numbers.
def multiply(s,n): return s*n#your code here
Implement a function which multiplies two numbers.
multiply = lambda x, y: int.__mul__(x,y)
Implement a function which multiplies two numbers.
def multiply(num1,num2): return num1 * num2 print((multiply(5,7)))
Implement a function which multiplies two numbers.
#your code here def multiply(a,b): return a*b #Performed the multiplication and returned the final outcome