Lists
Data Structures
Numbers
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Algorithms
Logic
Combination of List
Instructions
Below are Instructions for this Kumite.
Introduction
Given the two list or arrays, filter and combine the numbers into one list or arrays. There will only be numbers in the list.
Requirements
- There will be no negative number in the list
- The list must be ordered in ascending order.
- There must be no repeating number in the list.
- It must support an empty list.
Test Samples
Below are the test sample for this excercise
# Multiple list should be able to combine into one list
combine_list([1,2,3],[4,5,6])
> [1,2,3,4,5,6]
# Final list should be sorted
combine_list([3,2,1,5],[6,8,7])
> [1,2,3,5,6,7,8]
# There must be no repeating number in the list
combine_list([4,5,6],[7,7,8])
>[4,5,6,7,8]
# The will be no negative number in the list
combine_list([4,5,8],[99,0,11,665,-245])
> [0,4,5,8,11,99,665]
def combine_list(list1,list2):
return list(set(list(filter(lambda c: (c > 0), list1 + list2))))
import codewars_test as test
import random
# TODO Write tests
import solution # or from solution import example
def answer(list1,list2):
return list(set(list(filter(lambda c: (c > 0), list1 + list2))))
def randomTestGen(min,max,numTime):
newList = []
for i in range(numTime):
r = random.randint(min,max)
newList.append(r)
return newList
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Sample test case")
def test_group():
@test.it("List should be combine into one list")
def test_case():
test.assert_equals(combine_list([1,2,3],[4,5,6]), [1,2,3,4,5,6])
@test.it("List should be sorted")
def test_case():
test.assert_equals(combine_list([3,2,1,5],[6,8,7]),[1,2,3,5,6,7,8])
@test.it("There must be no repeating numbers")
def test_case():
test.assert_equals(combine_list([4,5,6],[7,7,8]), answer([4,5,6],[7,7,8]))
@test.it("Must support empty list")
def test_case():
test.assert_equals(combine_list([],[]), [])
@test.describe("Hidden Test Case")
def test_group():
@test.it("Random test case")
def test_case():
for i in range(20):
t1 = randomTestGen(-5,30, random.randint(5,100))
t2 = randomTestGen(-5,30, random.randint(5,100))
test.assert_equals(combine_list(t1,t2), answer(t1,t2))