शुरू करेंमुफ़्त में शुरू करें

Functions को lambda expressions में बदलना

इन तीन सामान्य तरीके से परिभाषित functions को lambda expressions में बदलें:

# दो संख्याओं में से बड़ी संख्या लौटाता है
def func1(x, y):
    if x >= y:
        return x

    return y
# किसी string में characters की गिनती करने वाला dictionary लौटाता है
def func2(s):
    d = dict()
    for c in set(s):
        d[c] = s.count(c)

    return d
# संख्याओं के squares के योग का square root लौटाता है
def func3(*nums):
    squared_nums = [n**2 for n in nums]
    sum_squared_nums = sum(squared_nums)

    return math.sqrt(sum_squared_nums)

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में कोडिंग इंटरव्यू प्रश्नों का अभ्यास

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Convert func1() to a lambda expression
lambda1 = ____
print(str(func1(5, 4)) + ', ' + str(lambda1(5, 4)))
print(str(func1(4, 5)) + ', ' + str(lambda1(4, 5)))
कोड संपादित करें और चलाएँ