Ad
Code
Diff
  • def find_multiples(n): return sum([i, 0][all([i % 4, i % 6])] for i in range(n))
    • find_multiples = lambda n: sum([i, 0][all([i % 4, i % 6])] for i in range(n))
    • def find_multiples(n): return sum([i, 0][all([i % 4, i % 6])] for i in range(n))
Code
Diff
  • #!/usr/bin/env python3
    """
    Debugging: FixDatTrash # 2
    """
    
    # constant:
    PI = 3.1415926535897
    
    
    class Calculator:
        """A calculator class."""
    
        def __init__(self, num):
            """Initialize attributes."""
            self.num = num
    
        def calculate_power(self, exp):
            """
            Calculates power of self.num.
            parameter `exp` is the exponent.
            """
            result = 1
            for exp in range(exp, 0, -1):
                result *= self.num
            return result
    
        def calculate_square_root(self):
            """Calculates square root of self.num."""
            return self.num ** 0.5
    
        def calculate_cube_root(self):
            """Calculates cube root of self.num."""
            return self.num ** (1 / 3)
    
        def calculate_circumference(self):
            """
            Calculates circumference of circle.
            self.num is the diameter of the circle.
            """
            return PI * self.num
        
    • def power(num, amount):
    • result = num
    • i = 0
    • while i < amount:
    • i += 1
    • result *= num
    • return result
    • def square_root(num):
    • return power(num, 0.5)
    • def cube_root(num):
    • return power(num, 1/3)
    • def get_pi():
    • return 22/7
    • def get_circumference(diameter):
    • return get_pi * diameter
    • #Your Checklist:
    • #(Optional: put a list of problems you solved or features you added here in lines of comments, along with the line number)
    • #[Example] 1: Fixed function syntax (Line 9)
    • #!/usr/bin/env python3
    • """
    • Debugging: FixDatTrash # 2
    • """
    • # constant:
    • PI = 3.1415926535897
    • class Calculator:
    • """A calculator class."""
    • def __init__(self, num):
    • """Initialize attributes."""
    • self.num = num
    • def calculate_power(self, exp):
    • """
    • Calculates power of self.num.
    • parameter `exp` is the exponent.
    • """
    • result = 1
    • for exp in range(exp, 0, -1):
    • result *= self.num
    • return result
    • def calculate_square_root(self):
    • """Calculates square root of self.num."""
    • return self.num ** 0.5
    • def calculate_cube_root(self):
    • """Calculates cube root of self.num."""
    • return self.num ** (1 / 3)
    • def calculate_circumference(self):
    • """
    • Calculates circumference of circle.
    • self.num is the diameter of the circle.
    • """
    • return PI * self.num
Code
Diff
  • def solution(param: list) -> bool:
        """Returns True if atleast 2 out of 3 booleans are True."""
        return sum([1 for p in param if p is True]) >= 2
        
        
        
    • public class Kumite {
    • public static boolean boolCheck(boolean[] bools) {
    • return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];
    • }
    • }
    • def solution(param: list) -> bool:
    • """Returns True if atleast 2 out of 3 booleans are True."""
    • return sum([1 for p in param if p is True]) >= 2
Code
Diff
  • find_multiples = lambda n: sum([i for i in range(n) if i % 4 == 0 or i % 6 == 0])
    • def find_multiples(n):
    • return sum([i for i in range(n) if i % 4 == 0 or i % 6 == 0])
    • find_multiples = lambda n: sum([i for i in range(n) if i % 4 == 0 or i % 6 == 0])
Code
Diff
  • def find_multiples(n):
        return sum([i for i in range(n) if i % 4 == 0 or i % 6 == 0])
    • def find_multiples(n):
    • total = 0
    • for i in range(0, n, 2):
    • if i % 4 == 0 or i % 6 == 0:
    • total += i
    • return total
    • return sum([i for i in range(n) if i % 4 == 0 or i % 6 == 0])

Prints H shape pattern using letter H's and returns number of H's passed as asn argument.

For example:

Input: 5

Output:


H   H
H   H
H   H
HHHHH
H   H
H   H
H   H

HHHHH
Code
Diff
  • def theletterh(howmuchh=1):
        for row in range(7):
            for col in range(5):
                if col in [0, 4] or (row in [3] and col in [1, 2, 3]):
                    print('H', end='')
                else:
                    print(end=' ')
            print()
        print()
        return 'H' * howmuchh
    #H return and H print (H😀😃😁)
    • def theletterh(howmuchh=1):
    • for i in range(howmuchh):
    • print('H')
    • for row in range(7):
    • for col in range(5):
    • if col in [0, 4] or (row in [3] and col in [1, 2, 3]):
    • print('H', end='')
    • else:
    • print(end=' ')
    • print()
    • print()
    • return 'H' * howmuchh
    • #H return and H print (H😀😃😁)
Code
Diff
  • def colour_of_fruit(fruit: str) -> str:
        """Returns the color of given fruit."""
        match fruit:
            case "Apple" | "Raspberry" | "Strawberry":
                return "Red"
            case "Orange":
                return "Orange"
            case "Banana" | "Lemon" | "Pineapple":
                return "Yellow"
            case "Avocado" | "Lime" | "Melon" | "Pear":
                return "Green"
            case "Blueberry" | "Huckleberry":
                return "Blue"
            case "Plum" | "Grape" | "Maquiberry":
                return "Purple"
            case _:
                return 'Not a fruit!'
        
    
        
    • def colouroffruit(fruit):
    • if fruit == "Apple":
    • return "Red"
    • elseif fruit == "Orange":
    • return "Orange"
    • elif fruit = "Blueberry":
    • return "Blue"
    • elif frut == "Pear":
    • return "Green"
    • elif fruit == "banana"
    • return "Yellow"
    • elif fruit = "Strawberry":
    • return "Red"
    • elif fruit == "Lemon":
    • return "Yellow"
    • elif fruit == "Lime":
    • print("Green")
    • elif fruit == "Raspberry"
    • return "Red":
    • elif fruit == "Pineapple":
    • def colour_of_fruit(fruit: str) -> str:
    • """Returns the color of given fruit."""
    • match fruit:
    • case "Apple" | "Raspberry" | "Strawberry":
    • return "Red"
    • case "Orange":
    • return "Orange"
    • case "Banana" | "Lemon" | "Pineapple":
    • return "Yellow"
    • elif fruit == "Melon":
    • return "Green"
    • if fruit == "Plum":
    • return "Purple"
    • elif fruit == "Strawberry":
    • return "Red"
    • elif fruit == "Cabbage"
    • return "Greem"
    • case "Avocado" | "Lime" | "Melon" | "Pear":
    • return "Green"
    • case "Blueberry" | "Huckleberry":
    • return "Blue"
    • case "Plum" | "Grape" | "Maquiberry":
    • return "Purple"
    • case _:
    • return 'Not a fruit!'
    • #Your Checklist:
    • #(Optional: put a list of problems you solved here in lines of comments, along with the line number)
    • #[Example] 1: Fixed if statement syntax (Line 2)
Code
Diff
  • def spawn_to_range(arr, val, ran):
        output = []
        for i in arr:
            output.append(i)
            if i == val:
                for j in range(ran-1):
                    output.append(i)
        return output
    • def spawn_to_range(arr, val, ran):
    • return
    • output = []
    • for i in arr:
    • output.append(i)
    • if i == val:
    • for j in range(ran-1):
    • output.append(i)
    • return output
Web Scraping
Code
Diff
  • 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 now
    • important_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 instead
    • return 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.'
Fundamentals
Arrays
Strings
Code
Diff
  • 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)
Fundamentals
Code
Diff
  • exec(bytes('敨汬彯敭獳条⁥‽慬扭慤›䠧汥潬圠牯摬✡', 'u16')[2:])
    • hello_message = lambda: 'Hello World!'
    • exec(bytes('敨汬彯敭獳条⁥‽慬扭慤›䠧汥潬圠牯摬✡', 'u16')[2:])
Code
Diff
  • exec(bytes('潳畬楴湯㴠氠浡摢⁡›㌢•湩猠牴渨
', 'u16')[2:])
    
    """
    ....................................................................................................
    .........:;;:..........::::::::,......,:::::,,............,::,..........,::::,,.........::,....::,..
    .......,%@@@@S:.......,@@@@@@@@+......:@@@@@@@%,..........+@@*..........%@@@@@#?,.......S@+...,@@;..
    .......%@@%%@@#,......,@@#SSSSS;......:@@SSSS@@%..........S@@#,.........S@#SS#@@*.......#@*...,@@;..
    ......,@@;..;@@;......,@@;............:@@:...*@@,........:@@@@;.........S@?..,%@#,......#@+...,@@;..
    ......,@@*,..;;,......,@@:............:@@,...;@@:........?@%?@%.........S@?...+@#,......#@+...,@@;..
    .......?@@@S*:........,@@S%%%%%,......:@@*++*#@S........,#@;;@@:........S@?,,:S@S.......#@#%%%S@@;..
    .......,?#@@@@?,......,@@@@@@@#,......:@@@@@@@S:........+@#..#@*........S@@@@@@@;.......#@@@@@@@@;..
    .........,;?S@@+......,@@+:::::.......:@@??@@%,.........S@%;;%@#,.......S@@###%;........#@?:::;@@;..
    ......:?*....%@%......,@@:............:@@,.;@@?........:@@@@@@@@;.......S@?,,...........#@+...,@@;..
    ......;@@;...%@%......,@@:............:@@:..*@@+.......?@#????#@%.......S@?.............#@+...,@@;..
    ......,S@@%?S@@+......,@@S%%%%%+......:@@:..,S@#,.....,#@*....+@@:......S@?.............#@+...,@@;..
    .......:S@@@@@*.......,@@@@@@@@?......:@@:...:@@?.....+@@,....,#@*......S@?.............#@*...,@@;..
    .........;++;,........,;;;;;;;;:......,;;,....:;:.....:;:..,:..:;:......:;:.............:;,...,;;,..
    ..........................................................;*%?......................................
    .........................................................,;+S#;.....................................
    .........................................................;*S@S*,....................................
    .........................................................:*S#S*,....................................
    .........................................................,*#S@*,....................................
    .........................................................,+@#@?:....................................
    .........................................................,;%%?*,....................................
    ..........................................................+***;,....,:..............................
    ..........................................................:?S%+......:,.............................
    ..........................................................,*S%+......::.............................
    ..........................................................,*%?;......,;.............................
    ...........................................................*%%+......:;.............................
    ...........................................................*SS*......;;.............................
    ..........................................................,*SS*.....:*,.............................
    ..........................................................,?%S?,...:*;..............................
    ..........................................................,*SSS+:;*?;...............................
    .......................................................,:;.+%?%??*;,................................
    ......................................................:+*?.;%?*,,...................................
    ....................................................,++**;.;S%+,....................................
    ...............................,,:::::,,...........,+*?+,,.+S%:.....................................
    ............................,:;+**++;;+++:........,+*%;..,,*S?,.....................................
    ..........................::+++%%%*+;;;;;**:......+*%;...,;?%*,.....................................
    ........................,+?**%S#@@#??*+;;;;**:...;*%+....;???+......................................
    ........................?S*%##@@@@@S%%%%?+;;+%?:,???....+S?*?:......................................
    .......................;#%SS@@@@S%*+::;*%S?+:+?%?%%:..,*S?+**,......................................
    ......................,%##%S@@#?+;;:::::;*%S?;;*?%%+;+%%*;+*:.......................................
    ......................+##S*S@#?+:,,.,,:;;;;?S%+;+**?%%*+;;*+........................................
    .....................,%##%;%#%+:........:*+;+****+***++;+*+,........................................
    .....................:S##?:*SS;...........:+;:;++********;..........................................
    .....................;S##*:*S%;.............::;;:;;++++:,...........................................
    .....................+###*:+SSS???*+:,.......,:;++;:,,,.............................................
    .....................+###?:+%#S?**?%%%*:.......:*?;:,,,::;:,........................................
    .....................;S@@%;+%#S+::::;*?%?:.....;?*;.;*SS###%*:......................................
    .....................?#@@#++*#S?+;;:,,:;?%+,...:?;*%##SS%%S@@#?:....................................
    ....................?##@@@%;+%S%?**++;:,:+??:...??##S?+;;+%@@@@S;,..................................
    ...................*S?##@@%*;+SS%??**++;:,:*%;.,%##%+:;?%%S#@@@@#+,.................................
    ..................:#%*S@@#+%;:*SSS%%??*++;:,+%+?#S?;;?SSS#%??%#@@S;.................................
    ..................?#?+%#@S++%;:*SSS#S%??*++:,;S##?;*SSS??+:.,:+S@@?,................................
    .................,SS?;?#@S;;**;:%%:;%#S%?*++;;S#S?%###%+:,.,,..+#@S:................................
    .................:#S?:+S##++*%+;+S*..:%#%?*++%##S#@@#?;:;+,;:,.,*#S;................................
    .................;@S?;:*S#S;;?*;:?S:...*#S?**####@@#?:,,;*+:....:%S+,...............................
    .................:##%+:;?#S*+S%+;;S?....+#S?%S@@@@S*;.:?%%S?*;..,*S+,...............................
    .................,S#S?;:+S#%;+S*;:%S,....+#S??S#@#*;;:,S%%?***+,:+?;,...............................
    ..................?#S%*;;*S#S;%?;:?#+.....;S++#@@?;+SS::%S?***+*+;+;,...............................
    ..................;#S%%*;+?#@+?%;:*@?......,:+S@#+;%SS%,.;%%**+*%*%*,...............................
    ..................:%#SS%?+*S@?*%;;?@S,.....,:*#@S;;#%?S*..,?%*++?%*;,...............................
    ...................+##SS%%?%#?+%+*?%#,.....,:*@@%:*#%??S:..,%?+;+S*,................................
    ...................,?####SSS#++%%@#*S:.....,:?@@?:?#%?*%*,::*?+:;S+,................................
    ....................:?#@@###?:+%#@#+?:.....:;%@@*;%#%?*?#S##%?;,+S?,................................
    .....................,+%??SS;:;%@@#;?+,....+*%@#*+##%%*?S@#S%*:,*#+.................................
    .......................:;::::::S@@S;%?*+;;;%?S@#+?##%%**%##%?+,:%#+.................................
    ............................,::+@@S+%**??%S#?#@S;*SSS%?*??%?+::*S#:.................................
    ............................,:;+S@#*%+;+++*%?@@%+@*+#%%????*;;?%#?,.................................
    .............................,:;%@@?S?*+++*?S@@*;+;:S#%%???*?%%SS:..................................
    .............................,;:*@@%%#%%??%%@@S+::;.;##S%%%%SS#S:...................................
    ..............................::;#@S%##SSS%S@@?;::;,.:%#######*:....................................
    ..............................,::?@#*S###S?#@#+::;:,..,;*%%%?:,.....................................
    ..............................,::+#%S%S#%*S#S*:::;,.......,.........................................
    ...............................,::?%??%%%S##*:::::..................................................
    ................................,;;S*+++*?%*;:;::,..................................................
    .................................:*S%?**?%%;::::,...................................................
    .................................,;?SS%%S%*;;::,....................................................
    ..................................,;?###S?;::,......................................................
    ....................................,;+*+:,,........................................................
    ....................................................................................................
    ....................................................................................................
    .....+#;..........,?#S;..........,?#S;............;#+...........,S?...........+SS*...........+SS*,..
    ....;@@+..........%@#@@:.........%@#@@:..........:#@+..........,%@%..........+@@@@*.........+@@#@*..
    ..,?@@@;.........:@S,+@?........:@S,+@?.........*@@@+.........;#@@%..........S@:,@#,........S@;,@@,.
    ..,@%%@;.........+@?.:@S........+@?.:@S........,@S?@+.........%#*@%.........,@#..S@:.......,@#,.S@:.
    ..,;.?@;.........*@*.,@#........*@*.,@#,.......,;.*@+.........;,:@%.........:@#..%@;.......,@#..%@;.
    .....?@;.........*@*.,@#........*@*.,@#,..........*@+...........:@%.........:@#..%@;.......:@#..%@;.
    .....?@;.........*@*.:@S........+@?.:@#...........*@+...........:@%.........,@#..S@:.......,@#,.%@;.
    .....?@;.........;@%.;@%........;@%.;@%...........*@+...........:@%.........,#@,.#@,.......,#@,.#@,.
    .....?@+.........,#@?S@+........,#@?S@+...........*@+...........:@%..........?@%?@%.........?@%?@%..
    .....*@;..........;#@@?..........;#@@?............*@+...........:@%..........,%@@S:.........,%@@S:..
    .....,,,...........,::............,::.............,,,............,,............::,............::,...
    ....................................................................................................
    
    Process finished with exit code 0
    
    
    
    """
    • exec(bytes('潳畬楴湯㴠氠浡摢⁡›㌢•湩猠牴渨
', 'u16')[2:])
    • """
    • ^&&7 Y@G.
    • !B#Y^ ^5#G^
    • .7PBP7: .^?PBP!.
    • ~@@! .:~7Y5PPY!.
    • ^&&^ .^?5P555JJJ?7777!!!7777?JJY5555YJ7~:.
    • Y@5 :!J5GPJ!: ....^^^^^^~^^^^^:...
    • :&@#JPP5?~.
    • .BBY!:. .........
    • ............... .........
    • ................................
    • ..................................
    • ..^~7????7~~^::.........::^^~!!77???7!~^:.
    • :!?YPBGGBBB###&&&##GPYYJJYYY5PGGGPP55YYY5PGGPYJ7.
    • :JY5&#7^::::::^~!!7YB&##BBBBGP?~^::........~5BP5P:
    • ~JG&!.......:^^^^:.^#&#B#BGGY..::::........^GP5J
    • .7G&~......:^^::::.^&&BP5PBG5:::.:. .::::.:5PP~
    • .^5#Y.......::::::.J@#Y~^~5BG7...:. .:::::~YPY~.
    • .:7B#^.........::.~&&G~^^~!PBP~... .::::::!PP7~.
    • ..:JBG~:........:?&@B7^^^~~7GBG?^...::::^7YPP?~!.
    • .:.:!PBGPYJJJJ5B&@&5!^^^^^~~!JGBGP5YYYY5PGPY!~!~
    • ::..:^7YPGBBBGPJ!^^^^^^^^~~~~~7?JY5555YJ7!~~~!.
    • :::....::!^:::::::^^^^^^~~~~~~~~!!^~~~~~!!!!:
    • :^::::::~^~77!~^^^^^~~~~~~!!7?J7:.^!!!!!!!:
    • :^^::::::::^7?J7....:~....~?~..:~!!!!!!!.
    • .^~^^^^^^^::::. . .:^!!!!!!!!:
    • .^~~~^^~^~^^^:. .. .~!!!!!!!!~:
    • .:^~!~~~~~~~~~~~!~~!!!!!!!!~^.
    • .:^~!!!!!!!!!!!!!!!~^:.
    • ...:::::::...
    • ....................................................................................................
    • .........:;;:..........::::::::,......,:::::,,............,::,..........,::::,,.........::,....::,..
    • .......,%@@@@S:.......,@@@@@@@@+......:@@@@@@@%,..........+@@*..........%@@@@@#?,.......S@+...,@@;..
    • .......%@@%%@@#,......,@@#SSSSS;......:@@SSSS@@%..........S@@#,.........S@#SS#@@*.......#@*...,@@;..
    • ......,@@;..;@@;......,@@;............:@@:...*@@,........:@@@@;.........S@?..,%@#,......#@+...,@@;..
    • ......,@@*,..;;,......,@@:............:@@,...;@@:........?@%?@%.........S@?...+@#,......#@+...,@@;..
    • .......?@@@S*:........,@@S%%%%%,......:@@*++*#@S........,#@;;@@:........S@?,,:S@S.......#@#%%%S@@;..
    • .......,?#@@@@?,......,@@@@@@@#,......:@@@@@@@S:........+@#..#@*........S@@@@@@@;.......#@@@@@@@@;..
    • .........,;?S@@+......,@@+:::::.......:@@??@@%,.........S@%;;%@#,.......S@@###%;........#@?:::;@@;..
    • ......:?*....%@%......,@@:............:@@,.;@@?........:@@@@@@@@;.......S@?,,...........#@+...,@@;..
    • ......;@@;...%@%......,@@:............:@@:..*@@+.......?@#????#@%.......S@?.............#@+...,@@;..
    • ......,S@@%?S@@+......,@@S%%%%%+......:@@:..,S@#,.....,#@*....+@@:......S@?.............#@+...,@@;..
    • .......:S@@@@@*.......,@@@@@@@@?......:@@:...:@@?.....+@@,....,#@*......S@?.............#@*...,@@;..
    • .........;++;,........,;;;;;;;;:......,;;,....:;:.....:;:..,:..:;:......:;:.............:;,...,;;,..
    • ..........................................................;*%?......................................
    • .........................................................,;+S#;.....................................
    • .........................................................;*S@S*,....................................
    • .........................................................:*S#S*,....................................
    • .........................................................,*#S@*,....................................
    • .........................................................,+@#@?:....................................
    • .........................................................,;%%?*,....................................
    • ..........................................................+***;,....,:..............................
    • ..........................................................:?S%+......:,.............................
    • ..........................................................,*S%+......::.............................
    • ..........................................................,*%?;......,;.............................
    • ...........................................................*%%+......:;.............................
    • ...........................................................*SS*......;;.............................
    • ..........................................................,*SS*.....:*,.............................
    • ..........................................................,?%S?,...:*;..............................
    • ..........................................................,*SSS+:;*?;...............................
    • .......................................................,:;.+%?%??*;,................................
    • ......................................................:+*?.;%?*,,...................................
    • ....................................................,++**;.;S%+,....................................
    • ...............................,,:::::,,...........,+*?+,,.+S%:.....................................
    • ............................,:;+**++;;+++:........,+*%;..,,*S?,.....................................
    • ..........................::+++%%%*+;;;;;**:......+*%;...,;?%*,.....................................
    • ........................,+?**%S#@@#??*+;;;;**:...;*%+....;???+......................................
    • ........................?S*%##@@@@@S%%%%?+;;+%?:,???....+S?*?:......................................
    • .......................;#%SS@@@@S%*+::;*%S?+:+?%?%%:..,*S?+**,......................................
    • ......................,%##%S@@#?+;;:::::;*%S?;;*?%%+;+%%*;+*:.......................................
    • ......................+##S*S@#?+:,,.,,:;;;;?S%+;+**?%%*+;;*+........................................
    • .....................,%##%;%#%+:........:*+;+****+***++;+*+,........................................
    • .....................:S##?:*SS;...........:+;:;++********;..........................................
    • .....................;S##*:*S%;.............::;;:;;++++:,...........................................
    • .....................+###*:+SSS???*+:,.......,:;++;:,,,.............................................
    • .....................+###?:+%#S?**?%%%*:.......:*?;:,,,::;:,........................................
    • .....................;S@@%;+%#S+::::;*?%?:.....;?*;.;*SS###%*:......................................
    • .....................?#@@#++*#S?+;;:,,:;?%+,...:?;*%##SS%%S@@#?:....................................
    • ....................?##@@@%;+%S%?**++;:,:+??:...??##S?+;;+%@@@@S;,..................................
    • ...................*S?##@@%*;+SS%??**++;:,:*%;.,%##%+:;?%%S#@@@@#+,.................................
    • ..................:#%*S@@#+%;:*SSS%%??*++;:,+%+?#S?;;?SSS#%??%#@@S;.................................
    • ..................?#?+%#@S++%;:*SSS#S%??*++:,;S##?;*SSS??+:.,:+S@@?,................................
    • .................,SS?;?#@S;;**;:%%:;%#S%?*++;;S#S?%###%+:,.,,..+#@S:................................
    • .................:#S?:+S##++*%+;+S*..:%#%?*++%##S#@@#?;:;+,;:,.,*#S;................................
    • .................;@S?;:*S#S;;?*;:?S:...*#S?**####@@#?:,,;*+:....:%S+,...............................
    • .................:##%+:;?#S*+S%+;;S?....+#S?%S@@@@S*;.:?%%S?*;..,*S+,...............................
    • .................,S#S?;:+S#%;+S*;:%S,....+#S??S#@#*;;:,S%%?***+,:+?;,...............................
    • ..................?#S%*;;*S#S;%?;:?#+.....;S++#@@?;+SS::%S?***+*+;+;,...............................
    • ..................;#S%%*;+?#@+?%;:*@?......,:+S@#+;%SS%,.;%%**+*%*%*,...............................
    • ..................:%#SS%?+*S@?*%;;?@S,.....,:*#@S;;#%?S*..,?%*++?%*;,...............................
    • ...................+##SS%%?%#?+%+*?%#,.....,:*@@%:*#%??S:..,%?+;+S*,................................
    • ...................,?####SSS#++%%@#*S:.....,:?@@?:?#%?*%*,::*?+:;S+,................................
    • ....................:?#@@###?:+%#@#+?:.....:;%@@*;%#%?*?#S##%?;,+S?,................................
    • .....................,+%??SS;:;%@@#;?+,....+*%@#*+##%%*?S@#S%*:,*#+.................................
    • .......................:;::::::S@@S;%?*+;;;%?S@#+?##%%**%##%?+,:%#+.................................
    • ............................,::+@@S+%**??%S#?#@S;*SSS%?*??%?+::*S#:.................................
    • ............................,:;+S@#*%+;+++*%?@@%+@*+#%%????*;;?%#?,.................................
    • .............................,:;%@@?S?*+++*?S@@*;+;:S#%%???*?%%SS:..................................
    • .............................,;:*@@%%#%%??%%@@S+::;.;##S%%%%SS#S:...................................
    • ..............................::;#@S%##SSS%S@@?;::;,.:%#######*:....................................
    • ..............................,::?@#*S###S?#@#+::;:,..,;*%%%?:,.....................................
    • ..............................,::+#%S%S#%*S#S*:::;,.......,.........................................
    • ...............................,::?%??%%%S##*:::::..................................................
    • ................................,;;S*+++*?%*;:;::,..................................................
    • .................................:*S%?**?%%;::::,...................................................
    • .................................,;?SS%%S%*;;::,....................................................
    • ..................................,;?###S?;::,......................................................
    • ....................................,;+*+:,,........................................................
    • ....................................................................................................
    • ....................................................................................................
    • .....+#;..........,?#S;..........,?#S;............;#+...........,S?...........+SS*...........+SS*,..
    • ....;@@+..........%@#@@:.........%@#@@:..........:#@+..........,%@%..........+@@@@*.........+@@#@*..
    • ..,?@@@;.........:@S,+@?........:@S,+@?.........*@@@+.........;#@@%..........S@:,@#,........S@;,@@,.
    • ..,@%%@;.........+@?.:@S........+@?.:@S........,@S?@+.........%#*@%.........,@#..S@:.......,@#,.S@:.
    • ..,;.?@;.........*@*.,@#........*@*.,@#,.......,;.*@+.........;,:@%.........:@#..%@;.......,@#..%@;.
    • .....?@;.........*@*.,@#........*@*.,@#,..........*@+...........:@%.........:@#..%@;.......:@#..%@;.
    • .....?@;.........*@*.:@S........+@?.:@#...........*@+...........:@%.........,@#..S@:.......,@#,.%@;.
    • .....?@;.........;@%.;@%........;@%.;@%...........*@+...........:@%.........,#@,.#@,.......,#@,.#@,.
    • .....?@+.........,#@?S@+........,#@?S@+...........*@+...........:@%..........?@%?@%.........?@%?@%..
    • .....*@;..........;#@@?..........;#@@?............*@+...........:@%..........,%@@S:.........,%@@S:..
    • .....,,,...........,::............,::.............,,,............,,............::,............::,...
    • ....................................................................................................
    • Process finished with exit code 0
    • """
Web Scraping

When I created this piece of code I thought it would be cool to develope a Codewars challenge that incorporated webscraping. This function scraps and retrieves the stats of a valid codewars username using the requests and BeautifulSoup module. If a valid username is entered the output will look as such:

Output:

username's Codewars stats:
	Member Since:Jan 2020
	Rank:4 kyu
	Honor:1500
	Leaderboard Position:#10,040
	Honor Percentile:Top 2.354%
	Total Completed Kata:776

Feel free to modify, and improve the code.

from bs4 import BeautifulSoup
import requests


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.'
    else:
        soup = BeautifulSoup(source.text, 'html.parser')
        stat_info = soup.findAll('div', class_='stat')
        name, member, rank, honor, position, percentage, katas = (stat_info[0],
                                                                  stat_info[3],
                                                                  stat_info[9],
                                                                  stat_info[10],
                                                                  stat_info[11],
                                                                  stat_info[12],
                                                                  stat_info[13])
        return f"{username}'s Codewars stats:\n\t{member.text}\n\t{rank.text}\n\t{honor.text}\n\t{position.text}\n\t{percentage.text}\n\t{katas.text}"
Fundamentals
Strings
Code
Diff
  • exec(bytes('楤敧瑳氽浡摢⁡㩳•⸢潪湩嬨猪⥝', 'u16')[2:])
    • digest=lambda s:' '.join([*s])
    • exec(bytes('楤敧瑳氽浡摢⁡㩳•⸢潪湩嬨猪⥝', 'u16')[2:])
Code
Diff
  • longest_string = lambda x: max(x.split(), key=lambda y: len(y))
    • const longestString = str => str.split(' ').reduce((a, b) => b.length > a.length ? b : a);
    • longest_string = lambda x: max(x.split(), key=lambda y: len(y))
Loading more items...