Ad
Code
Diff
  • def longest_string(a):
        return max(a.split(),key=len)
    • longest_string = lambda x: max(x.split(), key=lambda y: len(y))
    • def longest_string(a):
    • return max(a.split(),key=len)
Code
Diff
  • print("#中国 长垣")
    • #中国 长垣
    • print("#中国 长垣")
Code
Diff
  • def replicate(times, num):
        if times<=0:
            return []
        else:
            return [num]+replicate(times-1,num)
    print(replicate(8,5))
    • def replicate(times, num):
    • return [] if times <= 0 else [num] + replicate(times-1, num)
    • replicate(8,5)
    • if times<=0:
    • return []
    • else:
    • return [num]+replicate(times-1,num)
    • print(replicate(8,5))
Code
Diff
  • def f(a):
        return a
    print(f("Hello Python"))
    • print("Hello Python")
    • def f(a):
    • return a
    • print(f("Hello Python"))
Code
Diff
  • find_first_sub_string=lambda text,sub:[None, index:=text.find(sub)][index>-1]
    print(find_first_sub_string)
    
    • find_first_sub_string=lambda text,sub:[None, index:=text.find(sub)][index>-1]
    • find_first_sub_string=lambda text,sub:[None, index:=text.find(sub)][index>-1]
    • print(find_first_sub_string)
Code
Diff
  • def power(num, p):
        if p==0:
            return 1
        return num**p
            
    • def power(num, p):
    • return num ** p
    • if p==0:
    • return 1
    • return num**p