Session Ready
Exercise

Converting functions to lambda expressions

Convert these three normally defined functions into lambda expressions:

# Returns a bigger of the two numbers
def func1(x, y):
    if x >= y:
        return x

    return y
# Returns a dictionary counting charaters in a string
def func2(s):
    d = dict()
    for c in set(s):
        d[c] = s.count(c)

    return d
# Returns a squared root of a sum of squared numbers
def func3(*nums):
    squared_nums = [n**2 for n in nums]
    sum_squared_nums = sum(squared_nums)

    return math.sqrt(sum_squared_nums)
Instructions 1/3
undefined XP
  • 1

    Convert func1() to a lambda expression.

    • 2

      Convert func2() to a lambda expression.

    • 3

      Convert func3() to a lambda expression.