I query an api:
url = 'https://api.forecast.io/forecast/'+api_key+'/'+lat+','+lng
f = urllib2.urlopen(url)
json_string = f.read()
parsed_json = json.loads(json_string)
c = parsed_json['currently']
Some keys are defined, and others are not:
if 'temperature' in c:
I want to build an object of a few specific values:
vector = [c['temperature'], ... c['wind_speed']
In total, there should be 11 items. If a key is undefined, I want to replace the value in that position from another list with same indeces.
averages = [average_temp, ... average_wind]
Something like this:
# for each of the keys I want:
# if it is defined:
# add this value to the list
# else:
# add the value at the same index in the averages vector
I imagine you might index through both vectors at the same time. Of course, the first vector has not been defined yet. Somehow the values need to be indexed first. What is the pythonic way of doing this?