Skip to content

Instantly share code, notes, and snippets.

@AlexDrts
Created March 16, 2025 17:13
Show Gist options
  • Select an option

  • Save AlexDrts/32dc6b4dbed6c9f128b1812926bb1c1f to your computer and use it in GitHub Desktop.

Select an option

Save AlexDrts/32dc6b4dbed6c9f128b1812926bb1c1f to your computer and use it in GitHub Desktop.
# 1
# 1
# add = lambda x, y: x+y
# result = add(7,5)
# print(result)
# 2
# parity_check = lambda x: "Парне" if x % 2 == 0 else "Непарне"
# print(parity_check(4))
# print(parity_check(7))
# 3
# factorial = lambda n: 1 if n == 0 else n * factorial(n - 1)
# print(factorial(5))
# 2
# 1
# words = ["apple", "banana", "cherry", "date"]
# lengths = list(map(lambda word: len(word), words))
# print(lengths)
# 2
# words = ["apple", "kiwi", "banana", "pear"]
# sorted_words = sorted(words, key=lambda word: len(word))
# print(sorted_words)
# 3
# cube_dict = {x: (lambda x: x**3)(x) for x in range(1, 6)}
# print(cube_dict)
# 4
# coordinates = [(1, 2), (3, 5), (0, 0), (-1, 4)]
# sorted_coordinates = sorted(coordinates, key=lambda point: point[0]**2 + point[1]**2)
# print(sorted_coordinates)
# 3
# 1
# sentence = "Apple is a tasty fruit"
# count_vowel_words = lambda s: sum(1 for word in s.split() if word[0].lower() in "aeiou")
# print(count_vowel_words(sentence))
# 2
# strings = ["123", "45", "6789", "0"]
# filtered_strings = list(filter(lambda s: int(s) > 50, strings))
# print(filtered_strings)
# 3
# gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
# pairs = [(24, 36), (48, 180), (100, 250)]
# gcd_results = [gcd(a, b) for a, b in pairs]
# print(gcd_results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment