For an updated answer you can build a forEach
function in Python easily:
def forEach(list, function):
for i, v in enumerate(list):
function(v, i, list)
You could also adapt this to map
, reduce
, filter
, and any other array functions from other languages or precedence you'd want to bring over. For loops are fast enough, but the boiler plate is longer than forEach
or the other functions. You could also extend list to have these functions with a local pointer to a class so you could call them directly on lists as well.