import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(1 + 1, 2)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(1 + 1, 2)
Create a function wich takes in a list of tuples which contain a name of a worker and their annualy salary and return a
tuple with the five workers with the highest salary in descending order. Unluckily for you, the salary of some workers is unknown and hence represented as "-". Those workers shouldn't be in your final tuple.
Examples:
Input: [("max", "20000"), ("jason", "40000"), ("christian", "70000"), ("carl", "50000")] => Output: ("christian", "carl", "jason", "max")
Input: [("worker0", "-"), ("stephy", "100000"), ("king", "10000")] => Output: ("stephy", "king")
Input: [("ironman", "20000"), ("batman", "15000"), ("kenobi", "150000"), ("mr. x", "40000"), ("spiderman", "75000"), ("ramsay", "115000")] =>
Output: ("kenobi", "ramsay", "spiderman", "mr. x", "ironman")
Happy coding :-)
def sort_by_salary(workers):
filtered = list(filter(lambda x: x[1] != "-", workers))
if not filtered:
return tuple()
new = list(sorted(filtered, key=lambda x: int(x[1])))[::-1]
return tuple(i[0] for i in new)[:5]