-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.py
More file actions
43 lines (31 loc) · 1.21 KB
/
palindrome.py
File metadata and controls
43 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# # Palindromes are words that are the same when read forward and backward.
# text = input("Enter your text: ")
# text = text.replace(" ", "")
# text2 = text[::-1]
# text = text.lower()
# text2 = text2.lower()
# if len(text) > 1 and all(elem.lower() == elem2.lower() for elem, elem2 in zip(text, text2)) :
# print("It's a palindrome")
# else:
# print("Not a palindrome")
# Python sum function using the 'reduce' function
from functools import reduce
numbers= [3, 4, 6, 9, 34, 12]
result = reduce(lambda x, y: x + y, numbers, 10)
print(result)
# Use map to print the square of each numbers rounded
# to three decimal places
my_floats = [4.35, 6.09, 3.25, 9.77, 2.16, 8.88, 4.59]
result = list(map(round, [x**2 for x in my_floats], [3] * len(my_floats)))
print(result)
# OR
# map_result = list(map(lambda x: round(x ** 2, 3), my_floats))
# Use filter to print only the names that are less than
# or equal to seven letters
my_names = ["olumide", "akinremi", "josiah", "temidayo", "omoseun"]
filtered = list(filter(lambda x: len(x) <= 7, my_names))
print(filtered)
# Use reduce to print the product of these numbers
my_numbers = [4, 6, 9, 23, 5]
red = reduce(lambda x, y: x * y, my_numbers)
print(red)