How to Recursively Reduce a List Down to a Single Value
Normally when you map a list of values to a function you get back the same number of values you started with. The function is evaluated for each member of your list. When you want to reduce a list down to one we have the reduce function. As it turns out there is a reduce function in Python and R and it appears to work pretty similarly.
The way both implementations work is to recursively apply the function to successive pairs in the list. The result from each iteration is passed through to the next item and evaluated. Only the final result of these iterations is returned by the reduce functions.
As you can see the list of jedi names is returned as as single string. This pattern can be applied to numbers and more complicated lists as well.
Research Team Leader & GIS Analyst
3 年Thanks for sharing!
Operational Excellence | Decision Automation | AI | Digital Twins
3 年Data science interpretation on how multiple jedi become one with the force?