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


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

Re: [Python-de] Ein Problem mit Dictionarie, oder das Schlüssel werte problem

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Achim Domma <domma@procoders.net>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Ein Problem mit Dictionarie, oder das Schlüssel werte problem
Date Tue, 28 Aug 2018 17:02:21 +0200
Lines 49
Message-ID <mailman.194.1535469120.28281.python-de@python.org> (permalink)
References <pm39hu$1sc$1@tota-refugium.de> <pm3n94$b57$1@tota-refugium.de> <bce28b79-8311-71cd-eeb6-45e1371ec751@procoders.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de 2ecsbrXhfkfrsZ5U9cQmKgx6GCTvNQw2vh5+qrgp+wVA==
Return-Path <domma@procoders.net>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
Authentication-Results webhosting01.marketing-thom.de; spf=pass (sender IP is 90.186.234.211) smtp.mailfrom=domma@procoders.net smtp.helo=[192.168.178.22]
Received-SPF pass (webhosting01.marketing-thom.de: connection is authenticated)
Openpgp preference=signencrypt
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
In-Reply-To <pm3n94$b57$1@tota-refugium.de>
Content-Language en-US
X-PPP-Message-ID <20180828150221.3909.37942@webhosting01.marketing-thom.de>
X-PPP-Vhost procoders.net
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.29
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <bce28b79-8311-71cd-eeb6-45e1371ec751@procoders.net>
X-Mailman-Original-References <pm39hu$1sc$1@tota-refugium.de> <pm3n94$b57$1@tota-refugium.de>
Xref csiph.com de.comp.lang.python:5220

Show key headers only | View raw


Du bist da ziemlich im Off und solltest uns besser sagen, welches
Problem du lösen willst. Dein konkreter Fehler ist hier:

container.get("key"[0],0)

"key"[0] ist das erste Element von "key", also "k". Das "k" verwendest
du als Schlüssel. Den gibt's nicht, ergo bekommst du 0. Plus 1 ergibt 1,
das Ergebnis, das du zu sehen bekommst.

Grüße,
Achim

On Tuesday, 28 August, 2018 04:46 PM, Manfred Gil wrote:
> Am Dienstag, 28. August 2018, um 12:52:46 Uhr 
> schrieb Manfred Gil:
> 
>> Hallo Liste,
>>
>> ich will zur Laufzeit meines Programms ein dict erstellen mit einem 
>> Schlüssel und zwei werten. Der eine wert soll je nach anforderung
>> erhöht werden, also als Counter fungieren. Der zweite wert soll
>> erstmal nicht geändert werden wenn er erstellt wurde.
>>
>> Ich würde nun den Counter mit der get() Methode erhöhen und da liegt
>> mein Problem begraben. 
>>
>> Als kurzes und einfaches beispiel: 
>>
> [ Code gekürzt]
> 
> Noch mal zur Verdeutlichung, da Das Beispiel etwas Schlecht gewählt
> ist.
> 
> container = {'key' : [2, 'hallo']}
>                  ^
> ich würde gerne den wert 2 auf 3 erhöhen
> 
> container["key"][0] = container.get("key"[0],0) + 1 #(2)
> 
> hier gibt mir 
> 
> print(container['key'][0])
> 
> 1 als Ausgabe. Es sollte aber 3 sein.
> 
> 
> 
> 
> 

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next 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