now it is also hard to understand
def slow_sum(lst): return sum([int("".join([c for c in str(x)])) for x in sorted(lst, key=lambda x: str(x))]) if lst else 0
- def slow_sum(lst):
if not lst:return 0lst = sorted(lst, key=lambda x: str(x))lst = [int(str(num)) for num in lst]def recursive_addition(l):if len(l) == 1:return l[0]return l[0] + recursive_addition(l[1:])total = 0for num in lst:total += recursive_addition([num])return total- return sum([int("".join([c for c in str(x)])) for x in sorted(lst, key=lambda x: str(x))]) if lst else 0
not bad, but the parentheses were not needed
Fundamentals
you could have done better, I was not impressed
#import random <<< weak # Global variable to keep track of the current index _dice_index = 0 def dice(): global _dice_index choices = ["1", "2", "3", "3", "4", "5"]#icons are wack - change my mind! result = choices[_dice_index] _dice_index = (_dice_index + 1) % len(choices) return result
import random- #import random <<< weak
- # Global variable to keep track of the current index
- _dice_index = 0
- def dice():
return random.choice(["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"])- global _dice_index
- choices = ["1", "2", "3", "3", "4", "5"]#icons are wack - change my mind!
- result = choices[_dice_index]
- _dice_index = (_dice_index + 1) % len(choices)
- return result
import codewars_test as test # TODO Write tests import solution # or from solution import example @test.it("Basic tests") def basic_tests(): valid = ["1", "2", "3", "3", "4", "5"] # roll 100 times for _ in range(100): result = dice() test.expect(result in valid, f"Got {result} but expected one of {valid}")
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- @test.it("Basic tests")
- def basic_tests():
valid = ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]- valid = ["1", "2", "3", "3", "4", "5"]
- # roll 100 times
- for _ in range(100):
- result = dice()
- test.expect(result in valid, f"Got {result} but expected one of {valid}")
Return True if argument is greater than 2. Otherwise, make the argument greater than 2
Sinnlos..