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 `zip` to extract "sub-keys" for testing against, as

```
if (user,report) not in zip(*list(zip(*t2.keys()))[0:2]):
  #etc

```

Here, the `[0:2]` extracts only the first two components of the key.
You can't wildcard the key but you could replace the third key with None if it isn't there:

```
x = {('user','report'): {'dummy': 1}, ('user','report', 'unknown_key'): {'dummy': 2}, }

new_dict = dict(zip({(k[0], k[1], k[2] if len(k) == 3 else None) for k in x.keys()}, x.values()))

new_dict

{('user', 'report', 'unknown_key'): {'dummy': 1},
 ('user', 'report', None): {'dummy': 2}}

```

This way you'll always know the length of the key and you can test the last value.