how to create a list of lists

后端 未结 5 2097
孤独总比滥情好
孤独总比滥情好 2020-12-16 20:30

My Python code generates a list everytime it loops:

list = np.genfromtxt(\'temp.txt\', usecols=3, dtype=[(\'floatname\',\'float\')], skip_header=1)
         


        
5条回答
  •  孤街浪徒
    2020-12-16 20:56

    You want to create an empty list, then append the created list to it. This will give you the list of lists. Example:

    >>> l = []
    >>> l.append([1,2,3])
    >>> l.append([4,5,6])
    >>> l
    [[1, 2, 3], [4, 5, 6]]
    

提交回复
热议问题