[Python-de] Re: for unpacking

[email protected] (Stefan Ram) 10 Aug 2024 11:57:44 GMT
Newsgroups gmane.comp.python.general.german
Organization Stefan Ram
Message-ID <[email protected]>
[email protected] (Stefan Ram) schrieb oder zitierte:
>my_dict = {'a': 1, 'b': 2, 'c': 3}
>my_dict['b'] = 4
>print(my_dict)  # Output: {'a': 1, 'b': 4, 'c': 3}

  Man könnte hier nun sogar die Schreibweise "b = 9"
  verwenden, aber dann müßte man dafür "exec" aufrufen.

  Quelltext:

l =[ { 'a':1, 'b':2, 'c':3 },{ 'a':4, 'b':5, 'c':6 }]
for triple in l:
    exec( 'b = 9', None, triple )
print( l )

  , Ausgabe:

[{'a': 1, 'b': 9, 'c': 3}, {'a': 4, 'b': 9, 'c': 6}]

  .
_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]