def your_name(n="Taki"): return f"Hello {n}, you are very kool!"
your_name =lambda n = 'Taki': f"Hello {n}, you are very kool!"- def your_name(n="Taki"):
- return f"Hello {n}, you are very kool!"
import codewars_test as test from solution import your_name # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(your_name(), 'Hello Taki, you are very kool!') test.assert_equals(your_name("Lorelai"), 'Hello Lorelai, you are very kool!') test.assert_equals(your_name("Rocky"), 'Hello Rocky, you are very kool!')
- import codewars_test as test
- from solution import your_name
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(your_name(), 'Hello Taki, you are very kool!')
test.assert_equals(your_name("seraph776"), 'Hello seraph776, you are very kool!')- test.assert_equals(your_name("Lorelai"), 'Hello Lorelai, you are very kool!')
- test.assert_equals(your_name("Rocky"), 'Hello Rocky, you are very kool!')
Fundamentals
Strings
Fundamentals
Strings
def reverse_string(string): reversed_list = [string[letter] for letter in range(len(string) - 1, -1, -1)] return "".join(reversed_list)
from collections import deque- def reverse_string(string):
return string[::-1]- reversed_list = [string[letter] for letter in range(len(string) - 1, -1, -1)]
- return "".join(reversed_list)
Fundamentals
Strings
Another one thread using 'deque' method
from collections import deque def reverse_string(string): reversed_str = deque("") [reversed_str.appendleft(letter) for letter in string] return "".join(reversed_str)
- from collections import deque
- def reverse_string(string):
return string[::-1]- reversed_str = deque("")
- [reversed_str.appendleft(letter) for letter in string]
- return "".join(reversed_str)
Fundamentals
Strings
from collections import deque def reverse_string(string): dequed_str = deque(string) return ''.join([dequed_str.pop() for _ in range(len(dequed_str))])
- from collections import deque
- def reverse_string(string):
return string[::-1]- dequed_str = deque(string)
- return ''.join([dequed_str.pop() for _ in range(len(dequed_str))])
from itertools import compress def test(): string = "letters inside a string" digits = [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] result = compress(string, digits) return ''.join(list(result))
- from itertools import compress
- def test():
return "".join(map(lambda i: {'1': 't', '2': 'e', '3': 's', '4': 't'}[str(i)], range(1, 5)))- string = "letters inside a string"
- digits = [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
- result = compress(string, digits)
- return ''.join(list(result))
from functools import reduce def est_height(gender, dad_height, mom_height): match gender: case "boy": return reduce(lambda x, y: x + y, [dad_height, mom_height]) / 2 + 0.5 case "girl": return reduce(lambda x, y: x + y, [dad_height, mom_height]) / 2 - 0.5
est_height=lambda g,d,m:(d+m+[-1,1][g=="boy"])/2- from functools import reduce
- def est_height(gender, dad_height, mom_height):
- match gender:
- case "boy":
- return reduce(lambda x, y: x + y, [dad_height, mom_height]) / 2 + 0.5
- case "girl":
- return reduce(lambda x, y: x + y, [dad_height, mom_height]) / 2 - 0.5