How to pass dictionary as an argument of function and how to access them in the function
<p>I tried doing this:</p>

<pre><code>def func(dict):
    if dict[a] == dict[b]:
        dict[c] = dict[a]
    return dict

num =  { "a": 1, "b": 2, "c": 2}
print(func(**num))
</code></pre>

<p>But it gives in TypeError.
Func got an unexpected argument a</p>

<p>Two main problems:</p>

<ul>
<li>passing the ** argument is incorrect.  Just pass the dictionary; Python will handle the referencing.</li>
<li>you tried to reference locations with uninitialized variable names.  Letters a/b/c are literal strings in your dictionary.</li>
</ul>

<p>Code:</p>

<pre><code>def func(table):
    if table['a'] == table['b']:
        table['c'] = table['a']
    return table

num =  { "a": 1, "b": 2, "c": 2}
print(func(num))
</code></pre>

<hr>

<p>Now, let's try a couple of test cases: one with a &amp; b different, one matching:</p>

<pre><code>&gt;&gt;&gt; letter_count =  { "a": 1, "b": 2, "c": 2}
&gt;&gt;&gt; print(func(letter_count))
{'b': 2, 'c': 2, 'a': 1}

&gt;&gt;&gt; letter_count =  { "a": 1, "b": 1, "c": 2}
&gt;&gt;&gt; print(func(letter_count))
{'b': 1, 'c': 1, 'a': 1}
</code></pre>

python python-3.x