I have a Python list that contains duplicate items and I need to find the indices of those duplicate items. Here’s an example list that I’m working with:
my_list = [1, 2, 3, 4, 2, 5, 6, 3, 4]
In this code, I have a list my_list
that contains several duplicate items, namely 2
, 3
, and 4
. I want to find the indices of these duplicates in the list.
Could someone please suggest a way to find the indices of duplicate items in a Python list? I’m open to any suggestions, whether it’s using built-in functions or writing custom code. Thank you!