how to create a list of lists

后端 未结 5 2087
孤独总比滥情好
孤独总比滥情好 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:57

    First of all do not use list as a variable name- that is a builtin function.

    I'm not super clear of what you're asking (a little more context would help), but maybe this is helpful-

    my_list = []
    my_list.append(np.genfromtxt('temp.txt', usecols=3, dtype=[('floatname','float')], skip_header=1))
    my_list.append(np.genfromtxt('temp2.txt', usecols=3, dtype=[('floatname','float')], skip_header=1))
    

    That will create a list (a type of mutable array in python) called my_list with the output of the np.getfromtext() method in the first 2 indexes.

    The first can be referenced with my_list[0] and the second with my_list[1]

提交回复
热议问题