Lambda functions always return an iterator hence you would have to wrap that lambda call into a list
Define a function that returns the length of a string
def string_length(s):
length = len(s)
print(f"The length of '{s}' is {length}")
return length
Define a list of strings
strings = ["hello", "world", "python"]
Apply the function to each element in the list using map and a lambda function,
then convert the result to a list
lengths = list(map(lambda x: string_length(x), strings))
Print the resulting list of lengths
print(lengths)
This would execute the print statements
Define a function that returns the length of a string
def string_length(s):
length = len(s)
print(f"The length of '{s}' is {length}")
return length
Define a list of strings
strings = ["hello", "world", "python"]
Apply the function to each element in the list using map and a lambda function,
then convert the result to a list
lengths = map(lambda x: string_length(x), strings)
Print the resulting list of lengths
print(lengths)
But this would not