Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
from bs4 import BeautifulSoup import requests import shutil import os def get_codewars_stats(username): """Scraps, and retrieves Codewars stats of given username.""" output = f'{username}\'s Codewars stats:\n' source = requests.get(f'https://www.codewars.com/users/{username}', stream=True) # Verify request status. Using 404 would miss a wide ranges of other failed connections. if source.status_code == 200: soup = BeautifulSoup(source.text, 'html.parser') stat_info = soup.findAll('div', class_='stat') important_values = [info.text for info in stat_info[:5] + stat_info[6:]] # Get url to users avatar/profile pic img_url = ''.join([el for el in str(soup.findAll('figure')[0].findNext('img')).split(' ') if 'src' in el]).replace('src="', '') # Get image_url requests: img_source = requests.get(img_url, stream=True) # The filepath where data will be saved: filepath = os.path.join(os.getcwd(), 'CodeWars') # Make Codewars directory if it does mot exist: if not os.path.isdir(filepath): os.mkdir(filepath) with open(os.path.join(filepath, username + '.jpg'), 'wb') as img_obj: # Save user's avatar/profile pic: img_source.raw.decode_content = True shutil.copyfileobj(img_source.raw, img_obj) print('Profile pic has been downloaded') with open(os.path.join(filepath, 'codewars_stats.txt'), 'w', encoding='utf-8') as file_obj: # Save user's Codewars stats: for item in important_values: file_obj.write(item + '\n') print('CodewarsStats have been successfully downloaded') output += '\n\t'.join([i for i in important_values]) return output else: return 'Something went wrong, enter a valid Codewars username.'
- from bs4 import BeautifulSoup
- import requests
- import shutil
- import os
- def get_codewars_stats(username):
- """Scraps, and retrieves Codewars stats of given username."""
source = requests.get(f'https://www.codewars.com/users/{username}')# Verify request status:if source.status_code == 404:return 'Something went wrong, enter a valid Codewars username.'soup = BeautifulSoup(source.text, 'html.parser')stat_info = soup.findAll('div', class_='stat')# i'm not sure why we dont show all of stat_info in the version before this# Would like someone to implement showing Profiles, since that is an image (maybe represent as link to profile?)# slicing the profiles out is my workaround for nowimportant_values = [info.text for info in stat_info[:5] + stat_info[6:]]- output = f'{username}\'s Codewars stats:\n'
- source = requests.get(f'https://www.codewars.com/users/{username}', stream=True)
seperator = '\n\t' # sadly f-strings don't allow backslashes, so we need to define a separator here insteadreturn f'{username}\'s Codewars stats:\n\t{seperator.join(important_values)}'- # Verify request status. Using 404 would miss a wide ranges of other failed connections.
- if source.status_code == 200:
- soup = BeautifulSoup(source.text, 'html.parser')
- stat_info = soup.findAll('div', class_='stat')
- important_values = [info.text for info in stat_info[:5] + stat_info[6:]]
- # Get url to users avatar/profile pic
- img_url = ''.join([el for el in str(soup.findAll('figure')[0].findNext('img')).split(' ') if 'src' in el]).replace('src="', '')
- # Get image_url requests:
- img_source = requests.get(img_url, stream=True)
- # The filepath where data will be saved:
- filepath = os.path.join(os.getcwd(), 'CodeWars')
- # Make Codewars directory if it does mot exist:
- if not os.path.isdir(filepath):
- os.mkdir(filepath)
- with open(os.path.join(filepath, username + '.jpg'), 'wb') as img_obj:
- # Save user's avatar/profile pic:
- img_source.raw.decode_content = True
- shutil.copyfileobj(img_source.raw, img_obj)
- print('Profile pic has been downloaded')
- with open(os.path.join(filepath, 'codewars_stats.txt'), 'w', encoding='utf-8') as file_obj:
- # Save user's Codewars stats:
- for item in important_values:
- file_obj.write(item + '\n')
- print('CodewarsStats have been successfully downloaded')
- output += '\n\t'.join([i for i in important_values])
- return output
- else:
- return 'Something went wrong, enter a valid Codewars username.'
import unittest from solution import get_codewars_stats from bs4 import BeautifulSoup import requests class TestGetCodeWarsStats(unittest.TestCase): """Setup testing variables.""" def setUp(self) -> None: # Feel free to use your username as a test sample instead: self.username_sample = 'seraph776' self.expected = get_codewars_stats(self.username_sample) def test_get_codewars_stats(self): """Tests get_codewars stats function.""" self.assertEqual(get_codewars_stats(self.username_sample), self.expected) self.assertEqual(get_codewars_stats('invalid_username'), 'Something went wrong, enter a valid Codewars username.') if __name__ == '__main__': unittest.main()
- import unittest
- from solution import get_codewars_stats
- from bs4 import BeautifulSoup
- import requests
- class TestGetCodeWarsStats(unittest.TestCase):
- """Setup testing variables."""
- def setUp(self) -> None:
- # Feel free to use your username as a test sample instead:
self.username_sample = 'Luk-ESC'- self.username_sample = 'seraph776'
- self.expected = get_codewars_stats(self.username_sample)
- def test_get_codewars_stats(self):
- """Tests get_codewars stats function."""
- self.assertEqual(get_codewars_stats(self.username_sample), self.expected)
self.assertEqual(get_codewars_stats(''), 'Something went wrong, enter a valid Codewars username.')- self.assertEqual(get_codewars_stats('invalid_username'), 'Something went wrong, enter a valid Codewars username.')
- if __name__ == '__main__':
- unittest.main()
from dataclasses import dataclass, field @dataclass class Dinosaur: name: str meat_eater: bool = field(default=False) @staticmethod def find_trex(lst): for dinosaur in lst: if isinstance(dinosaur, Tyrannosaurus) and dinosaur.meat_eater and dinosaur.name == 'tyrannosaurus': return True return False @dataclass class Tyrannosaurus(Dinosaur): meat_eater: bool = field(default=True)
exec(bytes("楦摮瑟敲⁸‽慬扭慤愠㨠∠祔慲湮獯畡畲≳椠", 'u16')[2:])- from dataclasses import dataclass, field
- @dataclass
- class Dinosaur:
- name: str
- meat_eater: bool = field(default=False)
- @staticmethod
- def find_trex(lst):
- for dinosaur in lst:
- if isinstance(dinosaur, Tyrannosaurus) and dinosaur.meat_eater and dinosaur.name == 'tyrannosaurus':
- return True
- return False
- @dataclass
- class Tyrannosaurus(Dinosaur):
- meat_eater: bool = field(default=True)
import unittest from solution import Dinosaur, Tyrannosaurus class TestFindTRex(unittest.TestCase): """Test FindTRex class.""" def setUp(self) -> None: tyrannosaurus = Tyrannosaurus('godzilla') trex0 = Tyrannosaurus('tyrannosaurus') trex1 = Tyrannosaurus('tyrannosaurus', False) trex2 = Tyrannosaurus('trex') trex3 = Dinosaur('velociraptor', False) trex4 = Dinosaur('tyrannosaurus', True) trex5 = Dinosaur('dinosaur') trex6 = Dinosaur('tyrannosaurus') trex7 = Tyrannosaurus('allosaurus') trex8 = Dinosaur('triceratops') trex9 = Dinosaur('brachiosaurus') trex10 = Dinosaur('Dinosaur') self.test_samples = (((trex0, tyrannosaurus, trex4, 'Triceratops', trex5, trex6, tyrannosaurus), True), ((trex7, 'tyrannosaurus', trex10, trex4, tyrannosaurus, trex9, trex9), False), ((trex7, 'tyrannosaurus', trex8, trex4, tyrannosaurus, trex3, trex6), False), ((trex5, trex1, trex3, trex2, tyrannosaurus, trex4, trex0, trex1), True), ((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), False), ((trex9, trex9, trex6, trex5, tyrannosaurus, trex4, tyrannosaurus), False), (('tyrannosaurus', trex7, trex3, trex4, False, trex5, trex0, trex4, trex2), True), ((tyrannosaurus, trex7, tyrannosaurus, trex4, trex5, 'trex0', trex4, trex2), False), (('Brachiosaurus', 'Velociraptor', 'Triceratops', trex4, tyrannosaurus), False), ((trex9, trex9, trex6, trex5, tyrannosaurus, trex4, tyrannosaurus), False), ((trex1, trex10, 'trex4', trex5, trex0, trex8, tyrannosaurus, trex7, trex10), True),) def test_find_trex(self): for sample, expected in self.test_samples: self.assertEqual(Dinosaur.find_trex(sample), expected) if __name__ == '__main__': unittest.main()
import codewars_test as test- import unittest
- from solution import Dinosaur, Tyrannosaurus
@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(find_trex(["Brontosaurus", "Stegosaurus", "Velociraptor"]), False)test.assert_equals(find_trex(["Boba Fett", "Palm Tree", "Tyrannosaurus", "Croissant"]), True)test.assert_equals(find_trex([]), False)- class TestFindTRex(unittest.TestCase):
- """Test FindTRex class."""
- def setUp(self) -> None:
- tyrannosaurus = Tyrannosaurus('godzilla')
- trex0 = Tyrannosaurus('tyrannosaurus')
- trex1 = Tyrannosaurus('tyrannosaurus', False)
- trex2 = Tyrannosaurus('trex')
- trex3 = Dinosaur('velociraptor', False)
- trex4 = Dinosaur('tyrannosaurus', True)
- trex5 = Dinosaur('dinosaur')
- trex6 = Dinosaur('tyrannosaurus')
- trex7 = Tyrannosaurus('allosaurus')
- trex8 = Dinosaur('triceratops')
- trex9 = Dinosaur('brachiosaurus')
- trex10 = Dinosaur('Dinosaur')
- self.test_samples = (((trex0, tyrannosaurus, trex4, 'Triceratops', trex5, trex6, tyrannosaurus), True),
- ((trex7, 'tyrannosaurus', trex10, trex4, tyrannosaurus, trex9, trex9), False),
- ((trex7, 'tyrannosaurus', trex8, trex4, tyrannosaurus, trex3, trex6), False),
- ((trex5, trex1, trex3, trex2, tyrannosaurus, trex4, trex0, trex1), True),
- ((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), False),
- ((trex9, trex9, trex6, trex5, tyrannosaurus, trex4, tyrannosaurus), False),
- (('tyrannosaurus', trex7, trex3, trex4, False, trex5, trex0, trex4, trex2), True),
- ((tyrannosaurus, trex7, tyrannosaurus, trex4, trex5, 'trex0', trex4, trex2), False),
- (('Brachiosaurus', 'Velociraptor', 'Triceratops', trex4, tyrannosaurus), False),
- ((trex9, trex9, trex6, trex5, tyrannosaurus, trex4, tyrannosaurus), False),
- ((trex1, trex10, 'trex4', trex5, trex0, trex8, tyrannosaurus, trex7, trex10), True),)
- def test_find_trex(self):
- for sample, expected in self.test_samples:
- self.assertEqual(Dinosaur.find_trex(sample), expected)
- if __name__ == '__main__':
- unittest.main()
def hello_message(): t = str.maketrans('_mag', ' Wld') return ''.join( hello_message .__name__ .capitalize() .translate(t)[:-1] .replace('ess', 'or') + '!' )
exec(bytes('敨汬彯敭獳条‽慬扭慤›䠧汥潬圠牯摬✡', 'u16')[2:])- def hello_message():
- t = str.maketrans('_mag', ' Wld')
- return ''.join(
- hello_message
- .__name__
- .capitalize()
- .translate(t)[:-1]
- .replace('ess', 'or')
- + '!'
- )
collatz = lambda n: collatz([n//2, 3*n+1][n%2]) + 1 if n > 1 else 0
#collatz = c = lambda n, x=0: c( [ n//2, 3*n + 1 ][ n%2 ], x + 1 ) if n > 1 else x#collatz = c = lambda n: 1 + c( [ n//2, 3*n + 1 ][ n%2 ] ) if n > 1 else 0collatz=c=lambda n:1+c([n//2,3*n+1][n%2])if n>1else 0- collatz = lambda n: collatz([n//2, 3*n+1][n%2]) + 1 if n > 1 else 0