Ad
Code
Diff
  • def print_string_sum(string):
        print(f"{string}\n{len(string)}")
    
    print_string_sum("hello")
    
    • print("hello", sum(range(2, 4)), sep='\n')
    • def print_string_sum(string):
    • print(f"{string}\n{len(string)}")
    • print_string_sum("hello")

This refactor separates the counting logic from the main function, making the code more maintainable and easier to understand. Additionally, the function uses a generator expression instead of creating an intermediate list, which can save memory when dealing with large lists.

Code
Diff
  • def count_true_bools(lst):
        return sum(1 for item in lst if isinstance(item, bool) and item)
    
    def solution(lst):
        return count_true_bools(lst) >= 2
    
    • solution = lambda x: sum(b for b in x if isinstance(b, bool)) >= 2
    • def count_true_bools(lst):
    • return sum(1 for item in lst if isinstance(item, bool) and item)
    • def solution(lst):
    • return count_true_bools(lst) >= 2
Code
Diff
  • reverseGear = word => word ? 
        reverseString(word.substr(1)) + word.charAt(0):"";
    • reverseGear=word=>word?reverseString(word.substr(1))+word.charAt(0):"";
    • reverseGear = word => word ?
    • reverseString(word.substr(1)) + word.charAt(0):"";