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 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'}

```
```
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']

myDict = {}
for domain in a:
    myDict[domain] = []
    for link in b:
        if domain in link:
            myDict[domain].append(link)

```