首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python中生成列表时获取列表对象附加的消息内置方法

在python中生成列表时获取列表对象附加的消息内置方法
EN

Stack Overflow用户
提问于 2017-01-29 07:39:11
回答 1查看 3.6K关注 0票数 0

我正在尝试构建一个列表,其中包含列表中的第二个元素。我第一次抓取了一些链接并存储在links_2016

代码语言:javascript
复制
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

但是,当我打印月份时,我会在列表中得到内置的方法消息:

代码语言:javascript
复制
'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时,我只得到[],这意味着结果有问题。

我还需要计算月份列表中的元素,所以我想学习如何解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-29 08:09:32

希望现在起作用了

代码语言:javascript
复制
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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41918660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档