loops - Save result of each iteration python -
i'm trying use qpx express. want save airports origin , destination of each loop results. when send json request (origin : ory / designation : lax / solution 2) have 2 flights (perhaps flight connecting).
multivol = data['trips']['tripoption'] origine_air = [] destination_air = [] p in multivol : print("") multivol1 = p['slice'] prix = p['saletotal'] print prix q in multivol1 : multivol2 = q['segment'] duree_trip = q['duration'] duree_trip_h = duree_trip // 60 print duree_trip_h s in multivol2 : multivol3 = s['leg'] d in multivol3 : ori = d['origin'] dest = d['destination'] heure_ar = d['arrivaltime'] heure_de = d['departuretime'] vol_entier = ori + dest print vol_entier origine_air.append(ori)
i tried store result in list.
my result :
eur596.60 18 orylhr lhrlax eur596.60 20 orylhr lhrlax [u'ory', u'lhr', u'ory', u'lhr'] []
the result of list isn't expected. when can see going ory lax there flight connecting @ lrh (london) , in list there firsts flights (ory lhr) not second part of trip.
how can have of trip in list ?
thanks
robin
it seems main concern parsing string storing tokens list. perhaps need?
flights = ["orylhr","lhrlax"] #given list of flights, parse them breaking strings in half , storing each half in list origindest = [] in range(0,len(flights)): #this gets first 3 chars origin = flights[i][0:3] #this gets last 3 chars dest = flights[i][3:6] #append origindest.append(origin) origindest.append(origin)
output
['ory','lhr','lhr','lax']
Comments
Post a Comment