How to pass dictionary to functions?
<p>I want to pass dictionary to user defined functions and I need to do some calculation based on the dictionary values. It is not working for me with functions but works fine without using functions. I am not sure, what is wrong with code. Any help please? No error message.</p>

<p>Input:</p>

<blockquote>
  <p>"13-07-2016 12:55:46",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 12:57:50",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:00:43",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:01:45",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:02:57",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:04:59",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:06:51",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com" <br>
  "13-07-2016 13:07:56",user,192.168.10.100,192.168.10.20,CONNECT,200,"www.abc.com"</p>
</blockquote>

<p>Code:</p>

<pre><code>file_name = sys.argv[1]
fo = open(file_name, "rb")


def setdict():
   dico,i={},0

   line = fo.readline()
   for line in fo:
     date, user, proxy_ip, client_ip, access_method, con, sites = line.split(",")
     sites = sites.rstrip('\n')
     dico[i]= date, user, proxy_ip, client_ip, access_method, con, sites
   return dico

def display(dico):
   for k,v in dico.items():
      print k,v
</code></pre>

<p>When you write a function in Python using the <code>def</code> keyword, the function is not automatically executed. You are never calling your <code>setdict</code> or <code>display</code> functions, just defining them so they can be called later.</p>

<p>Add this line to the end of your script to actually call the functions you defined:</p>

<pre><code>display(setdict())
</code></pre>

<p>or more verbosely</p>

<pre><code>dico = setdict()
display(dico)
</code></pre>

python dictionary