Re: If a dictionary key has a Python list as its value!

Liste des GroupesRevenir à cl python 
Sujet : Re: If a dictionary key has a Python list as its value!
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram) (ram@zedat.fu-berlin.de (Stefan Ram))
Groupes : comp.lang.python
Date : 07. Mar 2024, 21:21:31
Autres entêtes
Organisation : Stefan Ram
Message-ID : <tutorial-20240307202019@ram.dialup.fu-berlin.de>
References : 1
Varuna Seneviratna <varunaseneviratna@gmail.com> wrote or quoted:
If a dictionary key has a Python list as its value, you can read the values
one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
     print(v)
No tutorial describes this, why?
What is the Python explanation for this behaviour?
  This is explained by extensionality: To find the behavior of   "for v in ...", the only thing one needs to know about "..."
  is its value. You could just as well have written:
l = d[ k ]
for v in l:
  . l can be any iterable. It does not matter where it came from.
  It does not matter that it cam from a dictionary. There are thousand
  places where it could have come from, and no tutorial can name them
  all.

Date Sujet#  Auteur
7 Mar 24 * If a dictionary key has a Python list as its value!2Varuna Seneviratna
7 Mar 24 `- Re: If a dictionary key has a Python list as its value!1ram@zedat.fu-berlin.de (Stefan Ram)

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal