Hi, ich benötige eine mehrdimensionale Liste. Werttypen sollen eine Vielzahl von Werten hinzugefügt werden. Wobei diese Werte über einen fortlaufend nummerierten Index wiedergefunden werden sollen. Die Werttypen sind ebenfalls in einem Integerwert verschlüsselt. ich bekomme aber nur einen `Keyerror: 0` memwerte = [] memwerte[werttyp].append(anzahl) memwerte[werttyp][anzahl] = wert Was mache ich falsch? Folgendes geht, ist ja aber nicht dass was ich will: memwert[wert] = wert Danke im Vorraus für Eure Hilfe Gruß Ron _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
--On 16. Juni 2005 14:35:12 +0200 Ron Opitz <ron.opitz@dts.de> wrote:
Hi,
ich benötige eine mehrdimensionale Liste.
Werttypen sollen eine Vielzahl von Werten hinzugefügt werden. Wobei diese Werte über einen fortlaufend nummerierten Index wiedergefunden werden sollen. Die Werttypen sind ebenfalls in einem Integerwert verschlüsselt.
ich bekomme aber nur einen `Keyerror: 0`
memwerte = [] memwerte[werttyp].append(anzahl) memwerte[werttyp][anzahl] = wert
Listen sind keine Arrays! list.append(item) hängt 'item' an die Liste hinten dran. D.h. Du kannst nur *über* den Index des Elements zugreifen aber *nicht* über das Element selber. Vielleicht möchtest Du aber Dictionaries statt dessen verwenden? -aj _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
On 16 Jun 2005, lists@andreas-jung.com wrote:
Listen sind keine Arrays! list.append(item) hängt 'item' an die Liste
Bei Python? Python Listen sind doch sehr array-ähnlich (abgesehen von der Möglichkeit, beliebig zu wachsen). ZB is der Zugriff auf ein bestimmtes Listenelement (per Index) doch O(1) oder? Auch beim iterieren "fühlt" es sich eher wie ein Array aber nicht wie ein (linked) Liste an. Karl _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
--On 16. Juni 2005 17:55:22 +0200 Karl Pflästerer <sigurd@12move.de> wrote:
On 16 Jun 2005, lists@andreas-jung.com wrote:
Listen sind keine Arrays! list.append(item) hängt 'item' an die Liste
Bei Python? Python Listen sind doch sehr array-ähnlich (abgesehen von der Möglichkeit, beliebig zu wachsen). ZB is der Zugriff auf ein bestimmtes Listenelement (per Index) doch O(1) oder? Auch beim iterieren "fühlt" es sich eher wie ein Array aber nicht wie ein (linked) Liste an.
Ähnlich, aber nicht so wie Du sie verwendest hast. Du hast in eine Liste eingefügt und einen assoziativen Zugriff probiert...das passt konzeptionell nicht...da ist halt die Frage, was Du überhaupt genau vorgehabt hast..jedenfalls sind Liste keine Dicts und Dicts sind keine Listen. -aj _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
On 16 Jun 2005, lists@andreas-jung.com wrote:
--On 16. Juni 2005 17:55:22 +0200 Karl Pflästerer <sigurd@12move.de> wrote:
On 16 Jun 2005, lists@andreas-jung.com wrote:
Listen sind keine Arrays! list.append(item) hängt 'item' an die Liste
Bei Python? Python Listen sind doch sehr array-ähnlich (abgesehen von der Möglichkeit, beliebig zu wachsen). ZB is der Zugriff auf ein bestimmtes Listenelement (per Index) doch O(1) oder? Auch beim iterieren "fühlt" es sich eher wie ein Array aber nicht wie ein (linked) Liste an.
Ähnlich, aber nicht so wie Du sie verwendest hast. Du hast in eine Liste
Ich? Der Originalcode ist nicht von mir. Es bleibt meine Behauptung: Python Listen sind eher Arrays (der Zugriff auf bestimmte Elemente, das Ändern von Elementen (a[i] = j) etc). Karl _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
Hallo Leute, in der master.cf von Postfix kann man fremde Programme pipen. Wie kann ich dort ein Python-Script einbinden? Hat das schon mal jemand gemacht und kann mir einen Tip geben? Ich weiss, das diese Frage eventuell hier nicht richtig platziert ist, aber ich habe Hoffnung ... Grusz Mathias -- Mathias Uebel www.meeloon.de ..:|:.. OpenSource for business ..:|:.. www.frame-network.de ---------------------------------------------------------------------------- -- _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
Hi Mathias, bitte stehle keine fremden Threads.. Am Donnerstag, 16. Juni 2005 21:42 schrieb Mathias Uebel:
Hallo Leute,
in der master.cf von Postfix kann man fremde Programme pipen. Wie kann ich dort ein Python-Script einbinden? Hat das schon mal jemand gemacht und kann mir einen Tip geben? Ich weiss, das diese Frage eventuell hier nicht richtig platziert ist, aber ich habe Hoffnung ...
kannste haben, ist wegen Rücksicht auf die, die es nicht interessiert, auf dem Weg zu Dir pers... Falls Du eine _gute_ Lösung zum Parsen von rfc2822 gemäßen Adressen hast, bin ich interessiert. Pete _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
On 16.Jun 2005 - 14:35:12, Ron Opitz wrote:
Hi,
ich benötige eine mehrdimensionale Liste.
Werttypen sollen eine Vielzahl von Werten hinzugefügt werden. Wobei diese Werte über einen fortlaufend nummerierten Index wiedergefunden werden sollen. Die Werttypen sind ebenfalls in einem Integerwert verschlüsselt.
ich bekomme aber nur einen `Keyerror: 0`
memwerte = [] memwerte[werttyp].append(anzahl) memwerte[werttyp][anzahl] = wert
Das macht irgendwie keinen Sinn. Erstmal fehlen die Initialisierungen von werttyp und anzahl und wert. Ausserdem erzeugst du eine leere Liste und willst gleich danach in dieselbe indizieren. Das geht nicht. Das hier sollte funktionieren (nicht getestet) memwerte = [] typliste = [1,2,3,4] anzahl = 4 wert = "Wert" for werttyp in typliste: memwerte.insert(werttyp,[]) for i in range(0,anzahl: memwert[werttyp].insert(i,"%s-%d-%d" % (wert, werttyp,i)) Damit erhaelst du das hier [ ["Wert-0-0", "Wert-0-1", "Wert-0-2", "Wert-0-3"], ["Wert-1-0", "Wert-1-1",..],..] Andreas -- Is that really YOU that is reading this? _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (6)
-
Andreas Jung
-
Andreas Pakulat
-
Hans-Peter Jansen
-
Mathias Uebel
-
Ron Opitz
-
sigurd@12move.de