Question: I have a script that reads a list of `users` and `reports` from a MySQL database and runs a function for each of the values. The script checks the db every 5 minutes and adds these value pairs to a dictionary. As I loop through I don't want to re-add value pairs that are still in the dictionary. I've had no issues handling that with this code:

```
if (user, report) not in t1.reports_to_call:
    t1.add(report, user)

```

My issue is that I want to also check a dictionary `t2.reports_requested` where the key is a tuple of three parts `user`, `report` and `some_unknown_id`. If there a way to run `not in` on a dictionary where you only know 2 of three elements and want to wildcard the third?

I have been also looking to see if I can refactor this secondary dictionary and move `some_unknown_id` out of the key as I do think it may be the case that the user/report pair is unique in this dictionary. But if I determine I need to wildcard the third value what is best way to do this?

```
{('user', 'report', 'some_unknown_id'): {}}

```

Answer: 
You can use `set` and check if a new pair it is a subset of the `t2.reports_requested.keys()`

```
values_exist = [True for k in reports_requested.keys() if set(["user","report"]).issubset(k)]
if not values_exist:
    print("Add new tuple")
    pass

```

For example:

```
reports_requested = {('user', 'report', 'some_unknown_id'): {}, ('user1', 'report', 'some_unknown_id'): {}, ('user1', 'report', 'some_unknown_id2'): {}}
new_pair = {'user1', 'report2'}

values_exist = [True for k in reports_requested.keys() if new_pair.issubset(k)]
if not values_exist:
#     print("Add new tuple")
    pass

```

Performance check with timeit: `1.06 µs ± 184 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)`
No, you cannot check for the existence of keys in a dict using wild-cards.

Make a dict of dicts:

```py
{('user', 'report'): {
    'some_unknown_id': {},
}

```

or even better:

```py
{'user': {
    'report': {
        'some_unknown_id' : {},
    },
}

```

Then you have the best of all worlds.

You can first check whether a user occurs, and if so, whether in combination with a report, and if so, whether in combination with some other identifier.