在python中使用3D列表根据元素的出现情况存储和修改元素的计数
我有一个包含十六进制数据的文件,每行的格式为55 12 3d 4e aa etc。我有一个从扫描整个文件中获得的唯一长度列表。另外,我通过扫描整个文件来获得这些唯一长度的计数。例如:在python中使用3D列表根据元素的出现情况存储和修改元素的计数,python,arrays,list,Python,Arrays,List,我有一个包含十六进制数据的文件,每行的格式为55 12 3d 4e aa etc。我有一个从扫描整个文件中获得的唯一长度列表。另外,我通过扫描整个文件来获得这些唯一长度的计数。例如: Line 1: 55,76,2e,44,12,54,aa,76,23,3e Line 2: 76,2e,44,54,76,23 Line 3: 55,23,65,78,90,e4,aa,67 and so on My expected output after including the below men
Line 1: 55,76,2e,44,12,54,aa,76,23,3e
Line 2: 76,2e,44,54,76,23
Line 3: 55,23,65,78,90,e4,aa,67
and so on
My expected output after including the below mentioned process will appear something like:
Length - 10 Count - 20000
EscLength - 2 Count - 10000
EscLength - 7 Count - 8000
Length - 4 Count - 5000
EscLength - 5 Count - 3000
EscLength - 7 Count - 2000
原始数据包含“转义内容”。我有一个算法来检测它们,并得到更新数据的长度。现在,我必须为每个唯一的原始长度找到转义内容的唯一长度,然后得到对应于原始数据的唯一长度的每个转义内容的计数
我试图用python构建一个3D列表,其中将包含[原始长度、转义内容长度、转义内容长度计数]。我无法更新计数。当我找到唯一的值和更新/插入计数时,情况有点复杂
for i in xrange(len(escCount_list)):
strspl = str(escCount_list[i]).split(',')
for strs in strspl:
if(strs == len(packet_list)-len(afterEsc_list) and strspl[0] == len(packet_list)):
escCount_list[i].append(len(packet_list)
escCount_list[i].append(len(packet_list)-len(afterEsc_list))
storeCount = escCount_list[i]
escCount_list[i].append(storeCount + 1)
if(strspl[0] == len(packet_list)):
escCount_list[i].append(len(packet_list)
escCount_list[i].append(len(packet_list)-len(afterEsc_list))
storeCount = escCount_list[i]
escCount_list[i].append(storeCount + 1)
当遇到新的长度时,我会尝试包含如下值:
escCount_list[rows].append(len(packet_list)-len(afterEsc_list))
escCount_list[rows].append(len(packet_list))
escCount_list[rows].append(1)
rows = rows + 1
cols = cols + 1
看起来我把我的剧本弄得一团糟。我必须解决大量的问题,因为我的要求,我在一个脚本上做所有的事情。有没有办法修改这个问题,或者用一个简单的方法来解决这个问题。PS:目前我在escCount\u列表[rows].append()行获取列表索引越界异常