How would one use higher-order functions (functions returning other functions) in Python?
This is my JavaScript example, whose programming concept I would like to use in Python as well. Let's say, for example, that I would like to wrap a string in an HTML element. In JavaScript, it would look like this:
var wrapInElement = function(ele) {
return function(inp) {
return "<" + ele + ">" + inp + "</" + ele + ">";
};
};
And then I would use it like this:
var names = ["Mike", "Tony", "John"];
names.map(wrapInElement("p"));
How could this look like in Python? Is there a way to write functions that return customized functions like in the example above? One could also write a class in Python that accomplishes this task but wouldn't that be too much for such a basic task?