[英]Python - Counter merges elements from list together
我有一個完整的Windows API調用列表:
listOfSequences =
['GetSystemDirectoryA',
'IsDBCSLeadByte',
'LocalAlloc',
'CreateSemaphoreW',
'CreateSemaphoreA',
'GlobalAddAtomW',
'lstrcpynW',
'LoadLibraryExW',
'SearchPathW',
'CreateFileW',
'CreateFileMappingW',
'MapViewOfFileEx',
'GetSystemMetrics',
'RegisterClipboardFormatW',
'SystemParametersInfoW',
'GetDC',
'GetDeviceCaps',
'ReleaseDC', ...... and so on .....]
由於其中一些事件發生多次,因此我想收集它們的發生次數。 因此,我使用了collections.Counter。 但這將一些API連接在一起:
lCountedAPIs = Counter(listOfSequences)
當我打印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,
因此,例如: HeapLock (參見A)未與其他API合並,但CharNextA與GetCurrentProcessId串聯(參見B)
有人可以告訴我為什么會這樣以及如何解決嗎?
在此先感謝&最好的問候:)
檢查您的列表定義。 Python將相鄰的字符串文字串聯在一起,因此您一定在中間的某個地方錯過了逗號:
listOfSequences = [
'GetSystemDirectoryA',
'IsDBCSLeadByte',
'LocalAlloc',
...
'CharNextA'
# ^ comma missing here
'GetCurrentProcessId',
...
]
這傷了我好幾次。
Counter
沒有做任何事情。 您必須在listOfSequences
出現11次'CharNextAGetCurrentProcessId'
。 您可以通過運行'CharNextAGetCurrentProcessId' in listOfSequences
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.