Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 3.x 向嵌套列表添加数据_Python 3.x_Web Scraping_Nested Lists - Fatal编程技术网

Python 3.x 向嵌套列表添加数据

Python 3.x 向嵌套列表添加数据,python-3.x,web-scraping,nested-lists,Python 3.x,Web Scraping,Nested Lists,任何帮助都将不胜感激!我正在抓取多个URL,并使用for循环迭代这些URL。我将把相关的数据放在单独的列表中。但是,我正在尝试将我的数据组织在一个列表中,以便与其他数据进行比较。。。我还没刮干净。如何迭代列表并将数据放入列表的每个元素中?这似乎没那么难。。。不知道我错过了什么 def get_info(item_urls)#, count): #count is being passed in, leaving this here for context for item in item

任何帮助都将不胜感激!我正在抓取多个URL,并使用for循环迭代这些URL。我将把相关的数据放在单独的列表中。但是,我正在尝试将我的数据组织在一个列表中,以便与其他数据进行比较。。。我还没刮干净。如何迭代列表并将数据放入列表的每个元素中?这似乎没那么难。。。不知道我错过了什么

def get_info(item_urls)#, count): #count is being passed in, leaving this here for context
    for item in item_urls:
        #get data and stuff from current URL

        data = ["beer", "is", "awesome!", "...", "for", "helping", "with", "my", "depression"]
        count = len(data) # counting data for a number, that I should have just made up :)
        table = [[] for i in range(0, count)]
        for truth in data:
            for i in range(0, count):
                list('table[{}]'.format(i)).append(truth)
                print(truth)
        for thing in table[0]:
            print(thing)
   return "borked"
我的假逻辑: 对于数据中的每个元素,将元素追加到表中


遍历所有URL后,我希望返回整个构建表。

myList[I]
遍历列表
myList[i][j]
遍历列表列表中的元素
j
是内部列表中元素的索引。

感谢您的响应,但我仍然感到困惑。'table=[[]表示范围内的I(0,计数)]表示数据中的真值:print(真值)表示范围内的j(0,计数):list(table[I][j]。append(真值))print(真值)'我不知道如何在注释中格式化代码。我很抱歉