Seite 1 von 1

Dict problem

Verfasst: Mittwoch 25. Mai 2011, 14:03
von pytino
Hallo zusammen

Ich bin auf der suche nach einem Algorithmus um ein Dictionary zu verbinden:

Ausgangsformat: domains={'server':('memory','time','queues'):'queue':('size','weight')}

Output:
server=> memory
server=> time
server=> queues
queue=> size
queue=>weight

Hoffe auf eure hilfe.

Gruss aus der Schweiz

Martin

Re: Dict problem

Verfasst: Mittwoch 25. Mai 2011, 14:21
von pillmuncher

Code: Alles auswählen

>>> domains = {'server':('memory', 'time', 'queues'), 'queue':('size', 'weight')}
>>> for key, values in domains.iteritems():
...     for value in values:
...         print key, '=>', value
...
queue => size
queue => weight
server => memory
server => time
server => queues
Für Python 3.x items() statt iteritems() verwenden.

Gruß,
Mick

Re: Dict problem

Verfasst: Montag 30. Mai 2011, 13:00
von pytino
Hallo pillmuncher

Vielen besten dank.

Gruss Tino