Useful Iterator functions in Python – 1

For efficient looping and faster execution of code, Python allows some useful iterator functions. In the module “itertools” many built-in iterators are present. Below are some useful iterators use in Python for Data Science:

  1. accumulate(iter, func) – It takes in two arguments, namely the iterable target and the function. Which has to follow at each iteration of value in target. Addition occurs default if function is missing. In case if there is no input for iterable then the output iterable is also empty.
  2. chain(iter1, iter2…) – It prints all values in iterable targets in succession mention in its arguments.python for data science
  3. from_iterable() – Its implementation is similar to chain(). But, the argument in this case list of lists or other iterable containers.
  4. compress(iter, selector) – This shows selectivity in printing the values from the pass container. The values are select according to Boolean list values. Which are pass as other arguments. If Boolean True occurs, it is print or else, it is skip.

  1. dropwhile(func, seq) – Only if the function in an argument returns False value for the first time, the character starts printing in this case.
  2. filterfalse(func, seq) – This iterator only prints those values that return false for the function pass.

So, to learn more about iterators in python for data science, please check this and this as well. Always keep in mind that learning data science is not the same as learning a language. It requires an approach, so plan your journey accordingly.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.