Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5221

Re: Ein Problem mit Dictionarie, oder das Schlüssel werte problem

From Manfred Gil <manfred-gil@t-online.de>
Newsgroups de.comp.lang.python
Subject Re: Ein Problem mit Dictionarie, oder das Schlüssel werte problem
Date 2018-08-28 17:24 +0200
Organization diese und das
Message-ID <pm3pf2$d5n$1@tota-refugium.de> (permalink)
References <pm39hu$1sc$1@tota-refugium.de> <dict.get-20180828155159@ram.dialup.fu-berlin.de>

Show all headers | View raw


Am Dienstag, 28. August 2018, um 14:52:40 Uhr 
schrieb Stefan Ram:

> Manfred Gil <manfred-gil@t-online.de> writes:
> >Ich würde nun den Counter mit der get() Methode erhöhen und da
> >liegt mein Problem begraben.   
> 
>   Sorry, das hatte ich übersehen, als ich schrieb, daß ich
>   nicht wisse, was Du machen willst!
> 
>   Meinst Du:
> 
>   main.py
> 
> dict = {'key' : [2, 'hallo']}
> print( dict )
> 
> dict['key'][0] += 1
> print( dict )
> 
> dict[ 'key' ][ 0 ]= dict.get( 'key' )[ 0 ] + 1 
> print( dict )
> 
>   transcript
> 
> {'key': [2, 'hallo']}
> {'key': [3, 'hallo']}
> {'key': [4, 'hallo']}
> 
>   ? Allerding hatte ich den Eindruck, daß Du auch noch einen
>   Fehlwert (englisch "default value") festlegen willst.
>   Das habe ich jetzt erst einmal nicht berücksichtigt.
>   Solch ein Fehlwert (siehe auch »collections.defaultdict«)
>   kann immer nur für den Wert der Abbildung (englisch
>   "dictionary") als Ganzes festgelegt werden, nicht nur für
>   die erste Komponente (den Zahlenwert).
> 

Das war es was ich wollte. Danke.

Ich kann dir nicht sagen, wie oft ich irgend welche Klammern um das
ganze Schlüsselwort 'key' gelegt habe. Und Doch kam ich nicht darauf.

Ich glaube durch den Gedanken das get den schlüssel plus den ersten
wert aus der Liste brauche, habe ich die Klammern flasch gesetzt.

Das mit dem Fehlwert, sollte dann ein neuer Eintrag ins dict werden,
das werde ich aber wohl hinbekommen.

Danke nochmal, auch wenn ich mein Beispiel etwas kompliziert
formuliert hatte.

Gruß
Manfred

-- 
Letzte Worte eines Chemikers:
  "Laß das Reagenzglas bitte in _Ruhe_ stehen."

Back to de.comp.lang.python | Previous | NextPrevious in thread | Find similar


Thread

Ein Problem mit Dictionarie, oder das Schlüssel werte problem Manfred Gil <manfred-gil@t-online.de> - 2018-08-28 12:52 +0200
  Re: Ein Problem mit Dictionarie, oder das Schlüssel werte problem Manfred Gil <manfred-gil@t-online.de> - 2018-08-28 16:46 +0200
    Re: [Python-de]  Ein Problem mit Dictionarie, oder das Schlüssel werte problem Achim Domma <domma@procoders.net> - 2018-08-28 17:02 +0200
  Re: Ein Problem mit Dictionarie, oder das Schlüssel werte problem Manfred Gil <manfred-gil@t-online.de> - 2018-08-28 17:24 +0200

csiph-web