Update dictionary if in list
<p>I'm running through an excel file reading line by line to create dictionaries and append them to a list, so I have a list like:</p>

<pre><code>myList = []
</code></pre>

<p>and a dictionary in this format:</p>

<pre><code>dictionary = {'name': 'John', 'code': 'code1', 'date': [123,456]}
</code></pre>

<p>so I do this: <code>myList.append(dictionary)</code>, so far so good. Now I'll go into the next line where I have a pretty similar dictionary:</p>

<pre><code>dictionary_two = {'name': 'John', 'code': 'code1', 'date': [789]}
</code></pre>

<p>I'd like to check if I already have a dictionary with <code>'name' = 'John'</code> in <code>myList</code> so I check it with this function:</p>

<pre><code>def checkGuy(dude_name):
  return any(d['name'] == dude_name for d in myList)
</code></pre>

<p>Currently I'm writing this function to add the guys to the list:</p>

<pre><code>def addGuy(row_info):
        if not checkGuy(row_info[1]):
            myList.append({'name':row_info[1],'code':row_info[0],'date':[row_info[2]]})
        else:
            #HELP HERE
</code></pre>

<p>in this else I'd like to <code>dict.update(updated_dict)</code> but I don't know how to get the dictionary here.</p>

<p>Could someone help so <code>dictionary</code> appends the values of <code>dictionary_two</code>?</p>

<p>I would modify <code>checkGuy</code> to something like:</p>

<pre><code>def findGuy(dude_name):
   for d in myList: 
       if d['name'] == dude_name:
            return d
   else:
       return None # or use pass
</code></pre>

<p>And then do:</p>

<pre><code>def addGuy(row_info):
     guy = findGuy(row_info[1])
     if guy is None:
         myList.append({'name':row_info[1],'code':row_info[0],'date':[row_info[2]]})
     else:
         guy.update(updated_dict)
</code></pre>

python dictionary