Looping multiple values into dictionary
<p>I would like to expand on a previously asked question:</p>

<p><a href="http://stackoverflow.com/questions/39578130/nested-for-loop-with-unequal-entities">Nested For Loop with Unequal Entities</a></p>

<p>In that question, I requested a method to extract the location's type (Hospital, Urgent Care, etc) in addition to the location's name (WELLSTAR ATLANTA MEDICAL CENTER, WELLSTAR ATLANTA MEDICAL CENTER SOUTH, etc).</p>

<p>The answer suggested utilizing a for loop and dictionary to collect the values and keys.  The code snippet appears below:</p>

<pre><code>from pprint import pprint

import requests
from bs4 import BeautifulSoup

url = "https://www.wellstar.org/locations/pages/default.aspx"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")

d = {}
for row in soup.select(".WS_Content &gt; .WS_LeftContent &gt; table &gt; tr"):
title = row.h3.get_text(strip=True)
d[title] = [item.get_text(strip=True) for item in row.select(".PurpleBackgroundHeading a)]

pprint(d)
</code></pre>

<p>I would like to extend the existing solution to include the entity's address matched with the appropriate key-value combination.  If the best solution is to utilize something other than a dictionary, I'm open to that suggestion as well.</p>

<p>Let say you have a dict <code>d = {'Name': 'Zara', 'Age': 7}</code> now you want to add another value </p>

<blockquote>
  <p>'Sex'= 'female'</p>
</blockquote>

<p>You can use built in update method.</p>

<pre><code>d.update({'Sex': 'female' })
print "Value : %s" %  d

Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}
</code></pre>

<p>ref is <a href="https://www.tutorialspoint.com/python/dictionary_update.htm" rel="nofollow">https://www.tutorialspoint.com/python/dictionary_update.htm</a></p>

python loops dictionary beautifulsoup nested-loops