Wednesday 15 June 2011

python - Appending to the dictionary dynamically -


I am reading with a text file that has the following format:

  0.000 ff: DD FF: FF 4 126 48000 0.001 SD: FG er: SD5 125 67000 0.002 Q: Er FF: DD5 127 90000 0.003 XC: SD FF: DD5 127 9 0000 0.004 IO: UIHH: IJ 4 126 56000   

In the fourth column, 4 indicates the request and 5 indicates the reaction. I should make a dictionary with the second column in the form of keys if that line represents a request.
If the fourth column value is 5, then it indicates that the line corresponds to the response. In this case, look at the third column of that reaction, and if that third column is in the form of the dictionary key, then add 2th column as the value of that same key

In the above example, the desired result Is:

  {'ff: dd': 1, 2, 48000, qw: er, xc: sd}, {'IO: UV': 1, 0, 56000}   

For FF: DD, 1 indicates that there is only 1 request from FF: dd; 2 indicates that there are 2 responses to the FF: DD and 48000 FF: 6th column value of the request related to DD. I hope you understand the question. Please ask for any clarification. For Io: UV, because there is no response, 1 indicates the number of requests, 0 indicates the number of reactions and 6th column value of 56000 for this reaction.
I am doing all this to analyze network traffic

I do not know how to add value to dynamically. If there are fixed numbers of values, then I can manage, but this is a difficult situation. I'm using python2.6. Help is greatly appreciated thanks in advance! Use a dictionary with the keys

and value ones with tupals (requests, responses, 6 columns, [List of feedback keys])

No comments:

Post a Comment