{"id":25579,"date":"2021-11-23T08:55:20","date_gmt":"2021-11-23T03:25:20","guid":{"rendered":"https:\/\/python-programs.com\/?p=25579"},"modified":"2021-11-23T08:55:20","modified_gmt":"2021-11-23T03:25:20","slug":"python-itertools-dropwhile-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-itertools-dropwhile-function-with-examples\/","title":{"rendered":"Python Itertools.dropwhile() 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.dropwhile() Function:<\/strong><\/p>\n

Only after the func. in argument returns false for the first time does Python’s dropwhile() function return an iterator.<\/p>\n

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

dropwhile(function, sequence)<\/pre>\n

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

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

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

Given List = [6, 7, -3, -1, 4]<\/pre>\n

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

[-3, -1, 4]<\/pre>\n

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

Here it removes the positive numbers 6, 7 and the condition becomes false \r\nwhen the number the number is -3. so, the list remains unchanged afterwards.<\/pre>\n

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

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

Given List = [3, 6, 8, -4, -9, 10, 56]<\/pre>\n

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

[-4, -9, 10, 56]<\/pre>\n

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