How to count number of variables in a dictionary
<p>This is my current code to append different time to the same name id in a dict.</p>

<blockquote>
<pre><code>for name, date, time ,price in reader(f):
          group_dict[name].append([time])
</code></pre>
</blockquote>

<p>my question is how do i count the number of 'time' i have in each key in the dict ? </p>

<p>An example of output is</p>

<pre><code> {(name1): [time1, time2, time3]} 
</code></pre>

<p>and i am trying a way to include the count '3' inside</p>

<p>You can accomplish what you want by reassigning your key's value to include the length of its value:</p>

<pre><code>for key, value in yourDict.items(): # Change to .iteritems() if using Python 2.x
    yourDict[key] = value + [len(value)]
</code></pre>

<p>Or, you could do this using dictionary comprehension:</p>

<pre><code>yourDict = {key:value+[len(value)] for key, value in yourDict.items()} # Python 3.x
yourDict = {key:value+[len(value)] for key, value in yourDict.iteritems()} # Python 2.x
</code></pre>

python csv count