IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Creating a dictionary key on demand
What I want:

A dictionary that looks something like "SIG":"SIG1,SIG2,SIG3,...,SIG205,SIG206". It's currently called "output_buffers". The things I'm trying to add to it are devices. Each subsystem key has lots of devices.

My current thing that writes to it:

output_buffers[subsystem].append(device)

I do this every time I want to write a new device to the buffer for that particular subsystem.

Do I have to initialise the dictionary explicitly beforehand?

Edit: The language is Python.


Peter
[link|http://www.no2id.net/|Don't Let The Terrorists Win]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
Expand Edited by pwhysall April 10, 2006, 06:46:05 AM EDT
Expand Edited by pwhysall April 10, 2006, 06:59:45 AM EDT
New Do you mean this?
The dictionary looks like {"SIG": ["SIG1", "SIG2", etc.]}

Because a string doesn't have the append command.

If that's what you mean:

output_buffers = {}
output_buffers.setdefault(subsystem, []).append(device)

Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     Creating a dictionary key on demand - (pwhysall) - (1)
         Do you mean this? - (admin)

Besides, we all have spell check these days, right?
120 ms