Question: I have the following list of words:

```
x = ['Gaga', 'Gaga', 'Lam', 'Reem', 'Pal', 'Gaga','Lam']

```

I need to remove the words that appear only once, and return there indices, or positions.

```
y = ['Gaga', 'Gaga', 'Lam', 'Gaga', 'Lam']

loc = [0, 0, 0, 1, 1, 0, 0]

```

Any simple function to do this?

Answer: 
Alternative *one-liner* with **`pandas`** module and its [`pd.Series.duplicated()`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.duplicated.html) function:

```
In [80]: x = ['Gaga', 'Gaga', 'Lam', 'Reem', 'Pal', 'Gaga','Lam']

In [81]: (~pd.Series(x).duplicated(keep=False)).astype(int).tolist()
Out[81]: [0, 0, 0, 1, 1, 0, 0]

```

---

To remove all non-duplicates:

```
In [85]: s = pd.Series(x)

In [86]: s[s.duplicated(keep=False)].tolist()
Out[86]: ['Gaga', 'Gaga', 'Lam', 'Gaga', 'Lam']

```
You can also use list comprehension

```
x = ['Gaga', 'Gaga', 'Lam', 'Reem', 'Pal', 'Gaga', 'Lam'] 
y = [name for name in x if x.count(name) != 1]

```

output
======

['Gaga', 'Gaga', 'Lam', 'Gaga', 'Lam']