1

I have a program that works on a logfile to narrow it down to two items. The program works great except that sometimes it gets the two numbers backwards. For example, the two numbers it ends up with should be something like [1700, 1650], not [1650, 1700]. How can I make sure the higher value number is listed first [0] and the lower number listed second [1]?

import pylab  
from pylab import *  
from numpy import *  
from collections import Counter  

list_of_files=[('logfile.txt', 'Temp')]  
datalist = [( pylab.loadtxt(filename), label ) for filename, label in list_of_files]  
for data, label in datalist:  
  pylab.plot( data[:,0], data[:,1], label=label )  
  print data [:,1]    
  Temps = [k for k,v in Counter(data[:,1]).items() if v>1 and 1500<=k<2200]  
  print Temps 
  print ("Test="), 0.555*(Temps[0]-32)+.651*(Temps[1]-32)  
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
Rico
  • 329
  • 3
  • 9
  • Temps.sort() followed by Temps.reverse() ? – tom10 Oct 06 '13 at 16:40
  • 2
    The distance between the complexity of your script to the simplicity of your question is astounding – yuvi Oct 06 '13 at 16:53
  • FYI, if you use `pylab.plot` and `pylab.loadtext`, etc, you do not need to `from pylab import *` or `from numpy import *`. Just `import pylab` is sufficient. With the `*`, that means you can type `plot` instead (without saying `pylab.` first), but I recommend the first option. [See here](http://stackoverflow.com/a/2360808/1730674) – askewchan Oct 06 '13 at 17:00

1 Answers1

4

You can reverse sort your list like this:

Temps = [k for k,v in Counter(data[:,1]).items() if v>1 and 1500<=k<2200]
Temps = sorted(Temps, reverse=True)
boates
  • 117
  • 2