Files
30-seconds-of-code/snippets/for_each.md
2022-12-04 22:24:48 +02:00

421 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Execute function for each list element list maciv blog_images/green-plant.jpg 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