Ad
Fundamentals
Strings
Code
Diff
  • reverse_string = lambda string: string[::-1]
    
    # Example usage
    print(reverse_string("Hello, World!"))  # "!dlroW, Hello"
    print(reverse_string(""))  # ""
    print(reverse_string("a"))  # "a"
    print(reverse_string("ab"))  # "ba"
    print(reverse_string("abc"))  # "cba"
    • def reverse_string(string):
    • return string[::-1]
    • reverse_string = lambda string: string[::-1]
    • # Example usage
    • print(reverse_string("Hello, World!")) # "!dlroW, Hello"
    • print(reverse_string("")) # ""
    • print(reverse_string("a")) # "a"
    • print(reverse_string("ab")) # "ba"
    • print(reverse_string("abc")) # "cba"
Fundamentals
Logic
Code
Diff
  • def identify_data_type(n):
        return str(type(n))[8:-2]
    • def identify_data_type(n):
    • return n.__class__.__name__
    • return str(type(n))[8:-2]
Code
Diff
  • def Greeting(n, rank='', formal=0):
        determinant =  f'{rank} {n}' if formal and rank else f'{n}'
        return  f"Hello, {determinant}." if formal else f"Hey, {determinant}!"
    • def Greeting(n, rank='', formal=0):
    • greeting_word = "Hello" if formal else "Hey"
    • rank_str = f", {rank}" if rank and formal else ','
    • period = '.' if formal else '!'
    • return f"{greeting_word}{rank_str} {n}{period}"
    • determinant = f'{rank} {n}' if formal and rank else f'{n}'
    • return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"