I have two lists that i'm trying to split up so I can calculate the min and max values. The original list looks something like this:
vlim: [-6.44194488 -4.12189618]
vlim: [-0.35109226 0.90269746]
vlim: [-6.48470812 -4.06394711]
vlim: [-0.35046298 0.89800871]
vlim: [-6.50338849 -3.92795199]
and below you can see my script:
'''
Finding max and min vlim values
stars is lists[0] and gas is lists[1]
'''
from sys import argv
script, file = argv
with open(file) as f:
lists = ([], [])
for i, line in enumerate(f):
lists[i%2].append(line.strip())
## stars ##
minlist = []
maxlist= []
for i in range(0,len(lists[0])):
min_tmp = lists[0][i][7:18]
max_tmp = lists[0][i][19:30]
minlist.append(min_tmp)
maxlist.append(max_tmp)
## gas ##
minlist2 = []
maxlist2 = []
for i in range(0,len(lists[1])):
min_tmp2 = lists[1][i][7:18]
max_tmp2 = lists[1][i][19:30]
minlist2.append(min_tmp2)
maxlist2.append(max_tmp2)
print 'min star: ', max(minlist) #max bc negative values
print 'max star: ', min(maxlist)
print 'min gas: ', max(minlist2)
print 'max gas: ', max(maxlist2)
print''
print minlist
print''
print minlist2
print ''
print maxlist
I wanted to get rid of "vlim" and the brackets so I made two new lists; "minlist" which grabs the first number and "maxlist" which grabs the second. However, when I run max() on my gas list of maximum values, it doesn't pick out the actual maximum number:
min star: -7.48815421
max star: -3.84855181
min gas: -0.97899559
max gas: 0.9262432]
But you can see in the list below that there's a few numbers larger than what max() found, see line 2:
[' 0.90269746', ' 0.89800871', ' 0.91088956', ' 0.92375575', ' 0.91859109', ' 0.91030079', ' 0.91962641', '0.9262432]', ' 0.93031583', ' 0.96124881', \
' 0.97476199', ' 0.96566733', ' 0.96988751', ' 0.98140795', ' 0.96833185', ' 0.96395218', ' 0.9342977 ', ' 0.93163674', ' 0.89933621', ' 0.91770517', \
' 0.92165692', ' 0.90245033', ' 0.89833043', ' 0.91639502', ' 0.88873233', ' 0.87241003', ' 0.78407889', ' 0.69231273', ' 0.63886276', ' 0.60207066', \
' 0.58330105', ' 0.56990499', ' 0.55740021', ' 0.53945954', ' 0.51366063', ' 0.51928393', ' 0.46654584', ' 0.43496984', ' 0.39934928', ' 0.36126022', \
' 0.32730902', ' 0.30790094', ' 0.28456324', ' 0.25893116', ' 0.24498652', ' 0.23020501', ' 0.20266526', ' 0.18111511', ' 0.16598142', ' 0.18298263', \
' 0.15324247', ' 0.14616999', ' 0.11671082', ' 0.08299617', ' 0.04595069', ' 0.00824732', '-0.03321626', '-0.06159366', '-0.09449168', '-0.11242293', \
'-0.09726435', '-0.06395773', '-0.04232095', '-0.03196949', '-0.03847378', '-0.05006481', '-0.05253942', '-0.08344223', '-0.10788819', '-0.12003492', \
'-0.14036405', '-0.16807319', '-0.18165499', '-0.17822416', '0.1829591]', '-0.18755693', '-0.20039758', '-0.20103783']
Any idea how I can fix this? There's definitely something weird going on because I also had to use max() on "minlist2" (and min on "maxlist") to get it to give me the most negative number in the list (or smallest negative). Does it have something to do with the fact that there's both positive and negative numbers?
I'm really new to python so I may just be making some mistake in my script and not realizing it...
Sorry for the essay. Thanks!