Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 循环浏览列表并更改索引_Python_List_Loops_Zip_Flickr - Fatal编程技术网

Python 循环浏览列表并更改索引

Python 循环浏览列表并更改索引,python,list,loops,zip,flickr,Python,List,Loops,Zip,Flickr,我正在编写这段代码,它基本上是创建一个bbox,并将这个bbox拆分为许多较小的bbox,因为一个请求只能访问4000个元数据 #borders of the bbox longmax = 15.418483 #longitude top right longmin = 4.953142 #longitude top left latmax = 54.869808 #latitude top latmin = 47.236219 #latitude bottom #longitude lo

我正在编写这段代码,它基本上是创建一个bbox,并将这个bbox拆分为许多较小的bbox,因为一个请求只能访问4000个元数据

#borders of the bbox
longmax = 15.418483 #longitude top right
longmin = 4.953142 #longitude top left
latmax = 54.869808 #latitude top 
latmin = 47.236219 #latitude bottom


#longitude
longstep = longmax - longmin 
longstepx = longstep / 10 #longitudal steps the model shall perfom

print (longstepx)


#latitude
latstep = latmax - latmin
latstepx = latstep / 10 #latitudal steps the model shall perform

print(latstepx)


#create list of steps through coordinates longitude
llong = []
while longmin < longmax:
    longmin+=longstepx
    llong.append(+longmin)

print (len(llong)) #make sure lists have the same lengths


#create list of steps through coordinates latitude
llat = []
while latmin < latmax:
    latmin+=latstepx
    llat.append(+latmin)

print (len(llat)) #make sure lists have the same lengths


#create the URLs and store in list
urls = []
for lat,long,lat1,long1 in (zip(llat, llong,llat[+1],llong[+1])):
    for pages in range (1,5):
        print ("https://api.flickr.com/services/rest/method=flickr.photos.search&format=json&api_key=5..b&nojsoncallback=1&page={}&per_page=500&bbox={},{},{},{}&accuracy=1&has_geo=1&extras=geo,tags,views,description".format(pages,lat,long,lat1,long1))
print (urls)
我希望它与(zip(llong,llat)值“4”和“8”(这两个值有效),然后与 (zip(llong[+1],llat[+1])将值“5”和“9”插入到我的链接中。 此外,我希望它插入页码。 理想情况下,循环创建了一个带有四个数字4,5,8,9的链接。然后我希望它创建四个数字在1:5范围内的链接,保存链接并继续下一个四个数字,依此类推

但这根本不起作用

普,我希望我表达得足够清楚。 我不是在寻找一个现成的解决方案。我想学习,因为我对python非常陌生


谢谢。

我想你打算写:

#create the URLs and store in list
urls = []
for lat, long, lat1, long1 in (zip(llat, llong, llat[1:], llong[1:])):
    for page in range (1,5):
        print ("https://api.flickr.com/services/rest/method=flickr.photos.search&format=json&api_key=5..b&nojsoncallback=1&page={}&per_page=500&bbox={},{},{},{}&accuracy=1&has_geo=1&extras=geo,tags,views,description".format(page, lat, long, lat1, long1))
请注意区别:

In [1]: L = [1,2,3]

In [2]: L
Out[2]: [1, 2, 3]

In [3]: L[1]
Out[3]: 2

In [4]: L[1:]
Out[4]: [2, 3]

另外,请注意,我们可以将其替换为:

llong = []
while longmin < longmax:
    longmin+=longstepx
    llong.append(+longmin)
但是我想您打算这样做,在您的区域中包括longmin,而不包括longmax(与您的原始代码相反)


嘿。我改变了你的建议,效果很好。我很惊讶循环下的for循环竟然是这样工作的。我刚刚意识到
,以及我在发布问题时有意犯的错误。但我不明白的是你的解释…@Christoph:也许这很有用:我想知道为什么[1:end]不起作用。他们在3.3中更改了吗?1.
end
?2.在Python 2.x中,while循环和
range()
具有相同的性能。在Python 3.x中,range()的值是多少将按需生成列表的元素,这对于大型列表更好。应该是我列表中的一个数字。所有这些都应该是我列表中计算出的数字!
llong = []
while longmin < longmax:
    longmin+=longstepx
    llong.append(+longmin)
llong = range(longmin + longstepx, longmax + longstepx, longstepx)
llong = range(longmin, longmax, longstepx)