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`.
The [numpy\_indexed](https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP/blob/master/numpy_indexed/arraysetops.py#L86) package implements functionality of this type in a vectorized manner (disclaimer: I am its author). Sadly numpy lacks a lot of this functionality out of the box; I started numpy\_indexed with the intention of having it merged into numpy, but there are some backwards compatibility concerns, and big packages like that tend to move slowly. So that hasnt happened in the last 3 years; but the python packaging ecosystem works so well nowadays that just adding one more package to your environment is just as simple, really.

```
import numpy_indexed as npi
bools = npi.in_(targets, coo)

```

This will have a time-complexity similar to that of the solution posted by @fountainhead (logarithmic rather than linear, as per the currently accepted answer), but also the npi library will give you the safety of automated tests, and a lot of other convenient options, should you decide to approach the problem from a slightly different angle.