这是我的第一篇帖子,也许我不该来这里,但是还是试试吧...
如何从“for in”循环的输出中找到最大值和最小值?
我尝试了min()和max()函数,但出现以下错误...
TypeError: 'int' object is not iterable
这是我的代码...
import urllib2
import json
def printResults(data):
# Use the json module to load the string data into a dictionary
theJSON = json.loads(data)
# test bed for accessing the data
for i in theJSON["features"]:
t = i["properties"]["time"]
print t
def main():
# define a variable to hold the source URL
urlData = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
# Open the URL and read the data
webUrl = urllib2.urlopen(urlData)
#print webUrl.getcode()
if (webUrl.getcode() == 200):
data = webUrl.read()
# print out our customized results
printResults(data)
else:
print "Received an error from server, cannot retrieve results " + str(webUrl.getcode())
if __name__ == "__main__":
main()
任何指针都将不胜感激!