{"id":2628,"date":"2023-10-16T15:35:37","date_gmt":"2023-10-16T10:05:37","guid":{"rendered":"https:\/\/python-programs.com\/?p=2628"},"modified":"2023-11-10T11:43:22","modified_gmt":"2023-11-10T06:13:22","slug":"python-how-to-find-all-indexes-of-an-item-in-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-how-to-find-all-indexes-of-an-item-in-a-list\/","title":{"rendered":"Python How to Find all Indexes of an Item in a List"},"content":{"rendered":"

Lists are similar to dynamically sized arrays, which are declared in other languages(e.g., vector in C++ and ArrayList in Java). Lists do not have to be homogeneous all of the time, which makes it a very useful tool in Python. DataTypes such as Integers, Strings, and Objects can all be included in a single list. Lists are mutable, which means they can be changed after they’ve been created.<\/p>\n

An index refers to a position within an list.<\/p>\n

Given a list and item, the task is to print all indexes of occurrences of that item in the list<\/p>\n

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

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

givenlist<\/span>\u00a0=<\/span> [\"this\"<\/span>, \"is\"<\/span>,<\/span> \"the\",<\/span> \"new\", \"way\"<\/span>, \"to\" , \"learn\" , \"python\", \"which\" , \"is\" ,\"easy\" ,\"is\"<\/span>\u00a0]<\/span>\r\n\r\nitem<\/span>\u00a0= is<\/span><\/pre>\n

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

Indexes are : 1 9 11<\/pre>\n

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

Here \"is\" is present at the indices 1,9 and 11<\/pre>\n

Print the indices of occurrences of the item<\/h2>\n

There are several ways to find indices of item in list some of them are:<\/p>\n