title: Python create dictionary
body: <p>I am playing with BeautifulSoup and scraping bing search results. I don't plan on doing extensive scraping, I was just trying my hand at different data structures, etc.</p>
  
  <p>What I'm trying to do is create a dictionary with the different parsed results from my scrape. In other words, I need to put the link as one value, meta (description) info in another value.</p>
  
  <p>My end result should look something like this I would imagine:</p>
  
  <pre><code>{  '1' : {
       'link' : '&lt;a href="watever"&gt;Whatever&lt;/a&gt;',
       'description' : 'this is a great website'
     },
     '2' : {
       ... etc ...
     }
  }
  </code></pre>
  
  <p>My current code looks like this:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import requests
  import html5lib
  
  url = requests.get("http://www.bing.com/search?q=pet+toys")
  
  data = url.text
  
  soup = BeautifulSoup(data, "html5lib")
  
  for link in soup.find_all("li", "sa_wr"):
          record = {'link' : link.find_all("a")}
  
  print record
  </code></pre>
  
  <p>I'm obviously fairly new to Python...in PHP, I would have this handled, I am still just working on Python syntax, etc.</p>
  
  <p>Any help is appreciated. </p>
  
  <p><strong>Solution:</strong></p>
  
  <p>The code was working as it was supposed to, but I was seeing the dictionary with just one item as I was not iterating through it.</p>
  
  <p>Also, per recommendation, I added each dictionary to a list as opposed to a dictionary.</p>
  
  <pre><code>records = []
  
  for link in soup.find_all("li", "sa_wr"):
          for url in link.find_all("a"):
                  records.append( {'link' : url.get("href"), 'title' : url.contents} )
  
  for record in records:
          print record['title']
  </code></pre>