{"id":5340,"date":"2021-05-07T11:14:39","date_gmt":"2021-05-07T05:44:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=5340"},"modified":"2021-11-22T18:42:53","modified_gmt":"2021-11-22T13:12:53","slug":"python-remove-elements-from-a-list-while-iterating","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-remove-elements-from-a-list-while-iterating\/","title":{"rendered":"Python: Remove Elements from a List while Iterating"},"content":{"rendered":"

A collection is an ordered list of values. There could be various types of values. A list is a mutable container. This means that existing ones can be added to, deleted from, or changed.<\/p>\n

The Python list represents the mathematical concept of a finite sequence. List values are referred to as list items or list elements. The same value may appear multiple times in a list. Each event is regarded as a distinct element.<\/p>\n

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

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

givenlist = [\"hello\", \"this\", \"is\", \"this\", \"BTechGeeks\", \"this\", \"python\"]<\/pre>\n

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

['hello', 'is', 'BTechGeeks', 'python']<\/pre>\n

Delete Elements from a List while Iterating<\/h2>\n

There are several ways to remove elements from the list while iterating some of them are:<\/p>\n