Question: I struggle with this a lot, since I am pretty new to python and scrapy.
Let's say I have two lists

```
a = ['www.google.com', 'www.facebook.com', 'www.twitter.com']
b = ['www.google.com/adsense/', 'www.twitter.com/login', 'www.facebook.com/user/xx', 'www.facebook.com/user/yy', 'www.google.com/adwords']

```

Now I want to create a dictionary where the domain of the values matches that of the key, which would look like this:

```
c = {'www.google.com':['www.google.com/adsense/', 'www.google.com/adwords'], 'www.facebook.com':['www.facebook.com/user/xx', 'www.facebook.com/user/yy'], 'www.twitter.com':'www.twitter.com/login'}

```

any help on how to achieve this is appreciated guys <3

Answer: 
You can use a dictionary comprehension.

```
>>> {k:[x for x in b if x.split('/', 1)[0] == k] for k in a}
{'www.facebook.com': ['www.facebook.com/user/xx', 'www.facebook.com/user/yy'], 'www.twitter.com': ['www.twitter.com/login'], 'www.google.com': ['www.google.com/adsense/', 'www.google.com/adwords']}

```

Note that this differs from your expected output because the value for the key `"www.twitter.com"` is still a list.

I strongly recommend that you use the same data structure for every value in the dictionary, even if you end up with single-element lists. This way you can iterate over every element of `result.values()` without surprises (strings are iterables themselves) or do other operations with every value without having to worry about a `TypeError`.

Also note that all bets are off (because your question would be underspecified) if there can be elements with `"/"` in `a` and possibly with overlapping prefixes.
You can use a dict comprehension and the `str.startswith()` method to achieve this:

```
domains = ['www.google.com', 'www.facebook.com', 'www.twitter.com']
urls = ['www.google.com/adsense/', 'www.google.com/adwords', 
        'www.twitter.com/login', 'www.facebook.com/user/xx', 
        'www.facebook.com/user/yy']

c = {domain: [url for url in urls if url.startswith(domain)] for domain in domains}
>>> c
>>> {'www.google.com':['www.google.com/adsense/', 'www.google.com/adwords'], 
     'www.facebook.com':['www.facebook.com/user/xx', 'www.facebook.com/user/yy'], 
     'www.twitter.com':'www.twitter.com/login'}

```