{"id":25593,"date":"2021-11-23T08:54:53","date_gmt":"2021-11-23T03:24:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=25593"},"modified":"2021-11-23T08:54:53","modified_gmt":"2021-11-23T03:24:53","slug":"python-itertools-starmap-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-itertools-starmap-function-with-examples\/","title":{"rendered":"Python Itertools.starmap() Function with Examples"},"content":{"rendered":"

Itertools Module:<\/strong><\/p>\n

Itertools is a Python module that contains a collection of functions for dealing with iterators. They make it very simple to iterate through iterables such as lists and strings.<\/p>\n

Itertools.starmap() Function:<\/strong><\/p>\n

When an iterable is contained within another iterable and a function must be applied to both of them, starmap() is used. Each element of an iterable within another iterable is treated as a separate item by starmap(). It is comparable to a map (). This function belongs to the category of terminating iterators.<\/p>\n

A built-in function, a user-defined function, or even a lambda function can be used.<\/p>\n

Syntax:<\/strong><\/p>\n

starmap(function, iterable)<\/pre>\n

Parameters<\/strong><\/p>\n

function:<\/strong> This is Required. Procedures to be executed on iterable data.<\/p>\n

iterable:<\/strong> This is Required. Elements that will be passed to the function.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [(6, 2), (5, 5), (2, 9), (7, 1), (0, 3)]\r\nfunction: lambda a, b: a + b<\/pre>\n

Output:<\/strong><\/p>\n

[8, 10, 11, 8, 3]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [(6, 2), (5, 5), (2, 9), (7, 1), (0, 3)]\r\nfunction: lambda a, b: a * b<\/pre>\n

Output:<\/strong><\/p>\n

[12, 25, 18, 7, 0]<\/pre>\n

Itertools.starmap() Function with Examples in Python<\/h2>\n