I'm pretty new to python, and I'm working on a script that is reading in a log file and recording different registration events for each MAC address and the number of times they occur.
I am trying to structure the record to look like this as the MAC addresses are unique:
{'mac1' : { 'event1' : count1 , 'event2' : count2, ... } }
The number of unique MAC addresses is variable, as well as the types of events that can happen.
The best I've been able to do so far is this:
{('mac1', 'event1') : count1, ('mac1', event2') : count2, ('mac2', 'event1') : count 1, ...}
This makes it more difficult to print the output as I'd like to do this
mac1: event1=count1 event2=count2 event3=count3
mac2: event 2=count2 event3=count3
mac3: event1=count1 event3= count3
...
The code I have written so far (inside a loop which parses each logfile line):
I guess the next step when I sort out the record is how to get the data out of the record and print it to the screen or an output file
Thanks in advance...
I am trying to structure the record to look like this as the MAC addresses are unique:
{'mac1' : { 'event1' : count1 , 'event2' : count2, ... } }
The number of unique MAC addresses is variable, as well as the types of events that can happen.
The best I've been able to do so far is this:
{('mac1', 'event1') : count1, ('mac1', event2') : count2, ('mac2', 'event1') : count 1, ...}
This makes it more difficult to print the output as I'd like to do this
mac1: event1=count1 event2=count2 event3=count3
mac2: event 2=count2 event3=count3
mac3: event1=count1 event3= count3
...
The code I have written so far (inside a loop which parses each logfile line):
Code:
reg_MAC_ADDRESS = {} #inside loop if reg_MAC_ADDRESS.has_key((mac,event)): reg_MAC_ADDRESS[mac,event] += 1 else: reg_MAC_ADDRESS[mac,event] = 1
Thanks in advance...
Comment