pyhton code question
1. In the code below, plist is a list containing strings representing the names of some polygons.
a) Write a program that takes plist as input and returns another list lenlist that contains the length of each string in plist. You must use functional programming features (i.e. lambda function, map, reduce, filter etc.) to solve this.
b) Write a program that finds the largest number in the list lenlist. You must use functional programming features (i.e. lambda function, map, reduce, filter etc.) to solve this.
#code:
polygons_str = "Triangle, Square, Pentagon, Hexagon, Heptagon,
Octagon, Nonagon, Decagon, Hendecagon, Dodecagon, Tridecagon,
Tetradecagon, Pentadecagon"
plist = polygons_str.split(', ')
# a) your code below
# b) your code below
#code: polygons_str = "Triangle, Square, Pentagon, Hexagon, Heptagon, Octagon, Nonagon, Decagon, Hendecagon, Dodecagon, Tridecagon, Tetradecagon, Pentadecagon" plist = polygons_str.split(', ') # a) your code below lenlist = [len(x) for x in plist] print(lenlist) # b) your code below largest = max(lenlist) print(largest)
Get Answers For Free
Most questions answered within 1 hours.