python - 为什么我的函数只循环遍历列表中的三个元素

标签 python loops

我试图遍历列表中的所有元素(其中 8 个),但我的函数只提供了其中的 4 个。这是我作为个人项目制作的应用程序。

import urllib


def get_followers():
    count = 0
    link = ['http://twitter.com/statuses/user_timeline.xml?screen_name=beratmahmuzlu',     'http://twitter.com/statuses/user_timeline.xml?screen_name=lidiazuin', 'http://twitter.com/statuses/user_timeline.xml?screen_name=kelewele_boham', 'http://twitter.com/statuses/user_timeline.xml?screen_name=AwangHafizam', 'http://twitter.com/statuses/user_timeline.xml?screen_name=BRAYANLVN', 'http://twitter.com/statuses/user_timeline.xml?screen_name=zezol_pl', 'http://twitter.com/statuses/user_timeline.xml?screen_name=brysonwong', 'http://twitter.com/statuses/user_timeline.xml?screen_name=racsozara']
    while count < len(link):
        print link[count]
        link.pop()
        count = count + 1

最佳答案

您正在弹出列表并使循环基于列表的计数。

尝试使用 for 循环:

for lnk in link:
    print lnk

关于python - 为什么我的函数只循环遍历列表中的三个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6907075/

相关文章:

python - python2.5.2中的virtualenv

python - 重置列的 MultiIndex 级别

python - Apriori 算法即使对于少量数据也能显示大量结果

javascript - 访问嵌套对象 (JS) 中的信息

java - 嵌套 while 循环赋值在 Java 中给出了意想不到的结果

c - 使用无限循环时未打印消息

Python 添加到列表

python - 为什么 math.modf 返回 float ?

php - 我将如何循环这个?

c++ - 为什么这个 C++ 循环不是从 10 计数到 -5?