Given a set where each element is a string, how can I reduce the set into an integer that is the sum of the length of these strings?
setA = ("hi", "hello", "bye")
reduce(lambda .... for word in setA)
Calling reduce with some lambda function should return 10 (2 + 5 + 3).
I can do it with a couple lambdas, I think, but there must be a cleaner way.
If you really want to do this with a
lambdaandreduce, you can:But I’m not sure why you’d want to
reducefrom 0 instead of just usingsum, in which case your lambda is justlambda y: len(y), which is equivalent to justlen.