Question: I'm trying to reference an object that I'm matching for.

```
import re
list = ["abc","b","c"]
if any(re.search(r"a",i) for i in list):
    print("yes")
    print(i)

```

This works, just not the last `print` command.

Is there any way to do what I'm trying do to here?

Answer: 
This solution will scale worse for *large arrays*, for such cases the other proposed answers will perform better.

---

Here's one way taking advantage of [`broadcasting`](https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html):

```
(coo[:,None] == targets).all(2).any(1)
# array([False,  True,  True, False])

```

---

 **Details** 

Check for every row in `coo` whether or not it matches another in `target` by direct comparisson having added a first axis to `coo` so it becomes broadcastable against `targets`:

```
(coo[:,None] == targets)

array([[[False, False],
        [ True, False]],

       [[False, False],
        [ True,  True]],

       [[ True,  True],
        [False, False]],

       [[False, False],
        [False,  True]]])

```

Then check which `ndarrays` along the second axis have [`all`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.all.html) values to `True`:

```
(coo[:,None] == targets).all(2)

array([[False, False],
       [False,  True],
       [ True, False],
       [False, False]])

```

And finally use [`any`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.any.html) to check which rows have at least one `True`.
Here is a simple and intuitive solution that actually uses `numpy.isin()`, to **match tuples**, rather than match individual numbers:

```
# View as a 1d array of tuples
coo_view     = coo.view(dtype='i,i').reshape((-1,))
targets_view = targets.view(dtype='i,i').reshape((-1,))

result = np.isin(coo_view, targets_view)
print (result)
print(result.nonzero()[0])

```

**Output:**

```
[False  True  True False]
[1 2]

```

**Notes:**

1. The creation of these [views](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.ndarray.view.html) does not involve any copying of data.
2. The `dtype='i,i'` specifies that we want each element of the view to be a tuple of two integers