<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
On 26/10/10 21:20, masawudu bature wrote:
<blockquote cite="mid:203712.43705.qm@web58506.mail.re3.yahoo.com"
 type="cite">
  <style type="text/css"><!-- DIV {margin:0px;} --></style>
  <div
 style="font-family: times new roman,new york,times,serif; font-size: 12pt;">
  <div>How do I sum all occurrences of&nbsp; a number in a file?</div>
  <div>I have a file with a bunch of numbers, each on it's own line:</div>
  <div>&nbsp;</div>
  <div>5<br>
3</div>
  <div>11<br>
3<br>
7<br>
3<br>
5<br>
5<br>
11<br>
7</div>
  <div>7</div>
  <div>...</div>
  <div>How do i sum them up so that the output will be ,</div>
  <div>5 :&nbsp; 15</div>
  <div>3 :&nbsp;&nbsp; 9</div>
  <div>11:&nbsp; 22</div>
  <div>7 :&nbsp;&nbsp; 21</div>
  </div>
  <br>
</blockquote>
Assuming you know how to iterate through a file, you could try saving
the number of occurrences of each number in the file into a dictionary.<br>
Something like:<br>
<br>
if num in my_dict:<br>
&nbsp;&nbsp;&nbsp; my_dict[num] += 1<br>
else:<br>
&nbsp;&nbsp;&nbsp; my_dict[num] = 1<br>
<br>
HTH.<br>
Adam.<br>
</body>
</html>