python help separating lists in a text file -


i have text file hundreds of lists stored in text file. how separate lists , store them lists , search smallest second value between lists. open new ways of tackling problem. here first few 'lists' , attempt separate them

var line1=[["apr 02 2014 01: +0",0.6,"295"],["apr 03 2014 01: +0",0.641,"245"],["apr 04 2014 01: +0",0.625,"246"],["apr 05 2014 01: +0",0.665,"267"],["apr 06 2014 01: +0",0.632,"226"],["apr 07 2014 01: +0",0.672,"170"],["apr 08 2014 01: +0",0.655,"147"],["apr 09 2014 01: +0",0.654,"121"],["apr 10 2014 01: +0",0.62,"136"],["apr 11 2014 01: +0",0.629,"176"],["apr 12 2014 01: +0",0.68,"190"],["apr 13 2014 01: +0",0.677,"176"],["apr 14 2014 01: +0",0.73,"153"],["apr 15 2014 01: +0",0.587,"148"],["apr 16 2014 01: +0",0.591,"134"],["apr 17 2014 01: +0",0.612,"148"],["apr 18 2014 01: +0",0.593,"142"],["apr 19 2014 01: +0",0.612,"153"],["apr 20 2014 01: +0",0.654,"203"],["apr 21 2014 01: +0",0.713,"156"],["apr 22 2014 01: +0",0.711,"153"],["apr 23 2014 01: +0",0.625,"128"],["apr 24 2014 01: +0",0.629,"122"],["apr 25 2014 01: +0",0.603,"139"],["apr 26 2014 01: +0",0.6,"169"],["apr 27 2014 01: +0",0.589,"177"],["apr 28 2014 01: +0",0.585,"132"],["apr 29 2014 01: +0",0.612,"120"],["apr 30 2014 01: +0",0.626,"116"],["may 01 2014 01: +0",0.57,"142"] 

and attempt separate them

with open('test.txt','r') csvfile:   writer=csv.reader(csvfile,delimeter=' , ',quotechar=csv.quote_minimal)     row in writer:       print ','.join(row) 

ok, assuming representative input far format concerned:

var line1=[["apr 02 2014 01: +0",0.6,"295"],["apr 03 2014 01: +0",0.641,"245"]]; 

then following:

import json  open('test.txt', 'r') datafile:     data = datafile.read()  json_str = data.split('=', 1)[1].rstrip(';\n\r ') my_data = json.loads(json_str)  row in my_data:     print row  print "minimum second value" print min(my_data, key=lambda x: x[1]) 

which print:

[u'apr 02 2014 01: +0', 0.6, u'295'] [u'apr 03 2014 01: +0', 0.641, u'245'] minimum second value [u'apr 02 2014 01: +0', 0.6, u'295'] 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -