Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/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 多维列表,其中一个维度为列表_Python_Multidimensional Array_Struct - Fatal编程技术网

Python 多维列表,其中一个维度为列表

Python 多维列表,其中一个维度为列表,python,multidimensional-array,struct,Python,Multidimensional Array,Struct,我将浏览许多包含相同源代码的类似makefile。我试图找出一个特定的源文件中存在多少个项目。 我想要的是: foo.c 4[项目,项目,项目,项目] c条1[项目] 似乎我需要为每个makefile创建一个新的lstof项目,而我所做的就是删除它。 我试过很多其他的方法来解决这个问题 元组可以将列表作为其元素之一吗 for file in listOf Makefiles for line in Makeifle find code file (.c or .h) try:

我将浏览许多包含相同源代码的类似makefile。我试图找出一个特定的源文件中存在多少个项目。 我想要的是:
foo.c 4[项目,项目,项目,项目]
c条1[项目]
似乎我需要为每个makefile创建一个新的lstof项目,而我所做的就是删除它。 我试过很多其他的方法来解决这个问题 元组可以将列表作为其元素之一吗

for file in listOf Makefiles
for line in Makeifle
find code file (.c or .h)


    try:
        index = lstFilenames.index(strFilename)     # to determine if I have seen this file name yet
        #  Yes the file name is already in list
        lstOfFile = lstProjectNames[index]          # get list of projects that this file is seen in
        try:
            fileIndex = lstOfFile.index(myProject)  # check to see if the project is in the project list
        except:  # project not in list
            lstCount[index] +1                      # add one to count - I am counting the number of projects this file appears
            lstOfProjects.append(myProject)         # append the new project to list
    except:   # file name not found in list
            lstFilenames.append (strFilename)       #  put file in file name list 
            lstCount.append(1)                      # set count to one 
            lstOfProjects.append(myProject)         # add project name to project list

#************************************************************************** End of makefile  
lstProjectNames.append(lstOfProjects)  # add  project list to this list ( this list in indexed with teh file names and the counts)
del lstOfProjects[:]

你的
lstOfProjects[:]
行是罪魁祸首,因为你的
lstOfProjects
保存着你的
lstOfProjects
,一旦你删除了它的内容,它就会在
lstofProjectNames

中被删除,甚至删除del,并移动lstofProjectNames.append(lstOfProjects)在第二行的最后一行。我仍然得到错误的答案。我觉得我无法在我的lstof项目中获得新的项目列表,就好像我的项目在获得新文件时从未获得新的列表一样。所有这些变量都声明为=[]我想每个文件都需要一个新的lstof项目。那我该怎么做呢?因为我所有的文件都有相同的项目列表,我知道这不是真的,我想要的是:
CMD_AUTH.h1['ARC',]Labortex.c2['ARC','AFO']尝试用
lstOfProjects=[]替换
del lstOfProjects[:]
这将使您的
lstOfProjects
变量指向程序中新创建的列表,旧的列表将安全地保存在
lstofProjectNames
中,谢谢你。这就是我缺少的部分(还有一些小的逻辑问题):)