title: How can I modify my code to fit the function in order for it to run correctly?
body: <p>So I'm tasked with finding the most popular bid from a list of csv files like this</p>
  <pre><code>1,8dac2b,ewmzr,jewelry,phone0,9759243157894736,us,69.166.231.58,vasstdc27m7nks3
  2,668d39,aeqok,furniture,phone1,9759243157894736,jp,50.201.125.84,jmqlhflrzwuay9c
  3,622r49,arqek,vehicle,phone2,9759544365415694736,az,53.001.135.54,weqlhrerreuert6f
  4,6444t43,rrdwk,vehicle,phone9,9759543263245434353,au,54.241.234.64,weqqyqtqwrtert6f
  </code></pre>
  <p>and I have to determine the most popular bid, which is found in every 4th element within the csv file...</p>
  <p>so the thing that I'm gonna be looking for are the ones with (** **) around them, as indicated don below from the same example</p>
  <pre><code>1,8dac2b,ewmzr,**jewelry**,phone0,9759243157894736,us,69.166.231.58,vasstdc27m7nks3
  2,668d39,aeqok,**furniture**,phone1,9759243157894736,jp,50.201.125.84,jmqlhflrzwuay9c
  3,622r49,arqek,**vehicle**,phone2,9759544365415694736,az,53.001.135.54,weqlhrerreuert6f    
  4,6444t43,rrdwk,**vehicle**,phone9,9759543263245434353,au,54.241.234.64,weqqyqtqwrtert6f
  </code></pre>
  <p>So from my example, the output should be <code>vehicle</code></p>
  <p>Look at my previous question here where I asked the same thing:
  <a href="https://stackoverflow.com/questions/70256306/how-can-i-return-the-most-reoccuring-value-in-the-given-csv-list/70256538?noredirect=1#comment124195869_70256538">How can I return the most reoccuring value in the given csv list?</a></p>
  <p>Now with the help of a kind StackOverflow user <a href="https://stackoverflow.com/users/5387738/nikita-almakov">https://stackoverflow.com/users/5387738/nikita-almakov</a> , I was able to get this code...</p>
  <pre><code>import csv
  value_to_count = {}
      with open(&quot;tmp.csv&quot;, &quot;r&quot;) as f:
          reader = csv.reader(f)
          for row in reader:
              category = row[3]
              if category in value_to_count:
                  value_to_count[category] += 1
              else:
                  value_to_count[category] = 1
      count_to_value = sorted((v, k) for k, v in value_to_count.items())
  </code></pre>
  <p>However, when I tried to put this code under a function <code>popvote(filename)</code>, I encounter an issue which is that I don't know where to include the <code>filename</code> in the piece of code in order to get  the right output.</p>
  <p>Here is what I have so far:</p>
  <pre><code>import csv
  def popvote(filename):
      value_to_count = {}
      with open(&quot;tmp.csv&quot;, &quot;r&quot;) as f:
          reader = csv.reader(f)
          for row in reader:
              category = row[3]
              if category in value_to_count:
                  value_to_count[category] += 1
              else:
                  value_to_count[category] = 1
      count_to_value = sorted((v, k) for k, v in value_to_count.items())
      return count_to_value
  </code></pre>
  <p>However, the output, which as expected is not being printed correctly. I know that I haven't implemented <code>filename</code> into the function, and the reason is I don't know where to do so, can someone please help me figure this out?</p>