Files
30-seconds-of-code/snippets/for_each.md
2022-03-22 12:32:56 +02:00

406 B

title, tags, expertise, author, firstSeen, lastUpdated
title tags expertise author firstSeen lastUpdated
Execute function for each list element list beginner maciv 2020-03-15T12:54:08+02:00 2020-09-15T16:13:06+03:00

Executes the provided function once for each list element.

  • Use a for loop to execute fn for each element in itr.
def for_each(itr, fn):
  for el in itr:
    fn(el)
for_each([1, 2, 3], print) # 1 2 3