Travis build: 943

This commit is contained in:
Rohit Tanwar
2018-04-14 10:54:46 +00:00
parent c265a93ede
commit 3b9790bd73
17 changed files with 132 additions and 141 deletions

View File

@ -0,0 +1,7 @@
def bubble_sort(lst):
for passnum in range(len(lst) - 1, 0, -1):
for i in range(passnum):
if lst[i] > lst[i + 1]:
temp = lst[i]
lst[i] = lst[i + 1]
lst[i + 1] = temp

View File

@ -0,0 +1,6 @@
import types,functools
from pytape import test
from bubble_sort import bubble_sort
def bubble_sort_test(t):
t.true(isinstance(bubble_sort, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'<util.read_snippets.<locals>.snippet object at 0x7fc8ea4c6978> is a function')
test('Testing bubble_sort',bubble_sort_test)

View File

@ -1,7 +1,7 @@
from math import ceil
def chunk(arr, size):
def chunk(lst, size):
return list(
map(lambda x: arr[x * size:x * size + size],
list(range(0, ceil(len(arr) / size)))))
map(lambda x: lst[x * size:x * size + size],
list(range(0, ceil(len(lst) / size)))))

View File

@ -1,2 +1,2 @@
def compact(arr):
return list(filter(lambda x: bool(x), arr))
def compact(lst):
return list(filter(bool, lst))

View File

@ -1,7 +1,2 @@
from functools import reduce
def count_occurences(arr, val):
return reduce(
(lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0),
arr)
def count_occurrences(lst, val):
return len([x for x in lst if x == val and type(x) == type(val)])

View File

@ -8,8 +8,8 @@ def spread(arg):
return ret
def deep_flatten(arr):
def deep_flatten(lst):
result = []
result.extend(
spread(list(map(lambda x: deep_flatten(x) if type(x) == list else x, arr))))
spread(list(map(lambda x: deep_flatten(x) if type(x) == list else x, lst))))
return result

View File

@ -1,3 +1,2 @@
def difference(a, b):
b = set(b)
return [item for item in a if item not in b]

View File

@ -1,9 +1,9 @@
def insertion_sort(arr):
def insertion_sort(lst):
for i in range(1, len(arr)):
key = arr[i]
for i in range(1, len(lst)):
key = lst[i]
j = i - 1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
while j >= 0 and key < lst[j]:
lst[j + 1] = lst[j]
j -= 1
arr[j + 1] = key
lst[j + 1] = key

View File

@ -1,2 +1,2 @@
def is_lower_case(str):
return str == str.lower()
def is_lower_case(string):
return string == string.lower()

View File

@ -1,2 +1,2 @@
def is_upper_case(str):
return str == str.upper()
def is_upper_case(string):
return string == string.upper()

View File

@ -1,8 +1,2 @@
from copy import deepcopy
def max_n(arr, n=1):
numbers = deepcopy(arr)
numbers.sort()
numbers.reverse()
return numbers[:n]
def max_n(lst, n=1, reverse=True):
return sorted(lst, reverse=reverse)[:n]

View File

@ -1,7 +1,7 @@
from copy import deepcopy
def min_n(arr, n=1):
numbers = deepcopy(arr)
def min_n(lst, n=1):
numbers = deepcopy(lst)
numbers.sort()
return numbers[:n]

View File

@ -2,11 +2,11 @@ from copy import deepcopy
from random import randint
def shuffle(arr):
temp_arr = deepcopy(arr)
m = len(temp_arr)
def shuffle(lst):
temp_lst = deepcopy(lst)
m = len(temp_lst)
while (m):
m -= 1
i = randint(0, m)
temp_arr[m], temp_arr[i] = temp_arr[i], temp_arr[m]
return temp_arr
temp_lst[m], temp_lst[i] = temp_lst[i], temp_lst[m]
return temp_lst

View File

@ -1,5 +1,5 @@
def zip(*args, fillvalue=None):
max_length = max([len(arr) for arr in args])
max_length = max([len(lst) for lst in args])
result = []
for i in range(max_length):
result.append([