A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-March/002667.html below:

[Python-Dev] re: Using lists as sets

[Python-Dev] re: Using lists as setsJeremy Hylton jeremy@cnri.reston.va.us
Mon, 20 Mar 2000 12:28:28 -0500 (EST)
>>>>> "GVW" == gvwilson  <gvwilson@nevex.com> writes:

  GVW> On a semi-related note, can someone explain why programs are
  GVW> not allowed to iterate directly through the elements of a
  GVW> dictionary:

  GVW>    for (key, value) in dict:
              ...body...

Pythonic design rules #2:
     Explicit is better than implicit.

There are at least three "natural" ways to interpret "for ... in dict:"
In addition to the version that strikes you as most natural, some
people also imagine that a for loop should iterate over the keys or the
values.  Instead of guessing, Python provides explicit methods for
each possibility: items, keys, values.

Yet another possibility, implemented in early versions of JPython and
later removed, was to treat a dictionary exactly like a list: Call
__getitem__(0), then 1, ..., until a KeyError was raised.  In other
words, a dictionary could behave like a list provided that it had
integer keys.

Jeremy




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4