Python - uniquifying(!) dictionary keys -
I'm coming from a machine (via paxpackets) and I parse it using a regexes in a dictionary
For the line in the stream: If in the '/' line: # some mailing, the name of the # machine, the interface and the data for that interface = str (hostname) + results in receiving the data "+": "+ R.groups () [0] [0: 2] + r.groups () [2] dict [key] = str (line [3])And all this Works fine, I like so many lines I get it when I read it back
machine1: fe0 & lt; data & gt;
& lt; data & gt; < / Code> is a string or integer
Now I know that many data may be present for the interface, and it seems that in this case, whenever I encounter it, I still I am overwriting the value for the price. What I would like to do is to make something unique in such a way that there is a lot of information available for this interface. If there is 3 example or fe1 in fe0 4
machine1: fe0: 3
At that interval I have no problem that after an example tell me that 1 is.
Hope this is clear and someone can tell me in the right direction - Many thanks
You can create a list for each key, keeping all the values for that key:
<0> [0: 2] + r.groups () [2] for the line in the stream. Value = str (line [3]) d [key] .append (value)Edit: If you want the key / value specified in your question, you can do something like this Are:
d2 = {} for key, value in d.iteritems (): d2 ['% S:% D'% (key, len (values)] = '' value (str (v)) for value (v)
'.join () to be included in values in a single string here - it is not really clear from your question, if you want to know what that is.
Does not recommend the way it makes personal values more difficult.
Comments
Post a Comment