[英]Python - Counter merges elements from list together
I have a list full of Windows API calls: 我有一个完整的Windows API调用列表:
listOfSequences =
['GetSystemDirectoryA',
'IsDBCSLeadByte',
'LocalAlloc',
'CreateSemaphoreW',
'CreateSemaphoreA',
'GlobalAddAtomW',
'lstrcpynW',
'LoadLibraryExW',
'SearchPathW',
'CreateFileW',
'CreateFileMappingW',
'MapViewOfFileEx',
'GetSystemMetrics',
'RegisterClipboardFormatW',
'SystemParametersInfoW',
'GetDC',
'GetDeviceCaps',
'ReleaseDC', ...... and so on .....]
Since some of them occurs several times, I wanted to collected their number of occurences. 由于其中一些事件发生多次,因此我想收集它们的发生次数。 Thus, I used collections.Counter.
因此,我使用了collections.Counter。 But it concatenates some APIs together:
但这将一些API连接在一起:
lCountedAPIs = Counter(listOfSequences)
when I print the lCountedAPIs I get the folowing: 当我打印lCountedAPI时 ,得到以下提示:
Counter({'IsRectEmptyLocalAlloc': 2,
'DdePostAdvise': 3,
'DispatchMessageWGetModuleFileNameA': 2,
'FindResourceExW': 50318,
'ReleaseDCGetModuleFileNameW': 7,
'DefWindowProcAGetThreadLocale': 1,
'CoGetCallContext': 40,
'CoGetTreatAsClassGetCommandLineA': 1,
'GetForegroundWindowGetSystemDirectoryW': 1,
'GetModuleHandleWGetSystemTimeAsFileTime': 2,
'WaitForSingleObjectExIsChild': 1,
'LoadIconAGetWindowsDirectoryW': 2,
'GlobalFreeLocalAlloc': 10,
'GetMapModeCreateSemaphoreW': 1,
'HeapLock': 11494, <---------- A
'CharNextAGetCurrentProcessId': 11, <---------- B
'RemovePropWGetStartupInfoA': 1,
'GetTickCountGetVersionExW': 55,
So for ex.: HeapLock (see A) was not merged with another API But CharNextA was concatenated with GetCurrentProcessId (see B) 因此,例如: HeapLock (参见A)未与其他API合并,但CharNextA与GetCurrentProcessId串联(参见B)
Can somebody tell me why this happens and how to fix that ? 有人可以告诉我为什么会这样以及如何解决吗?
Thanks in advcance & best regards :) 在此先感谢&最好的问候:)
Check your list definition. 检查您的列表定义。 Python concatenates adjacent string literals, so you must have missed a comma somewhere in the the middle:
Python将相邻的字符串文字串联在一起,因此您一定在中间的某个地方错过了逗号:
listOfSequences = [
'GetSystemDirectoryA',
'IsDBCSLeadByte',
'LocalAlloc',
...
'CharNextA'
# ^ comma missing here
'GetCurrentProcessId',
...
]
This has bitten me several times. 这伤了我好几次。
Nothing in Counter
does that. Counter
没有做任何事情。 You must necessarily have 11 occurrences of 'CharNextAGetCurrentProcessId'
in listOfSequences
. 您必须在
listOfSequences
出现11次'CharNextAGetCurrentProcessId'
。 You can check this by running 'CharNextAGetCurrentProcessId' in listOfSequences
. 您可以通过运行
'CharNextAGetCurrentProcessId' in listOfSequences
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.