我正在尝试构建一个列表,其中包含列表中的第二个元素。我第一次抓取了一些链接并存储在links_2016中
for i in links_2016:
parsed = urlparse.urlparse(i)
path = parsed[2]
pathlist = path.split("/")
list_pathlist.append(pathlist)
#get the months
months = []
for i in range(0,44): #there are 44 elements in list_pathlist
list_pathlist[i][2] #get the second element
months.append但是,当我打印月份时,我会在列表中得到内置的方法消息:
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>
'06'
<built-in method append of list object at 0x103c85170>在这之后,当我做print months时,我只得到[],这意味着结果有问题。
我还需要计算月份列表中的元素,所以我想学习如何解决这个问题。
发布于 2017-01-29 08:09:32
希望现在起作用了
for i in links_2016:
parsed = urlparse.urlparse(i)
path = parsed[2]
pathlist = path.split("/")
list_pathlist.append(pathlist)
#get the months
months = []
for i in range(0,len(list_pathlist)): #there are 44 elements in list_pathlist
months.append(list_pathlist[i][2]) #you are actually getting the third item
#since list indice start at 0, if you want the second item do [1]
print(months)要计算月份列表中的元素,请执行len(months)
https://stackoverflow.com/questions/41918660
复制相似问题