[Python-Dev] Re: Sets: elt in dict, lst.include - really begs for a PEP

Barry A. Warsaw barry@digicool.com
Wed, 31 Jan 2001 11:50:10 -0500

>>>>> "MZ" == Moshe Zadka <moshez@zadka.site.co.il> writes:

    MZ> Basic response: I *love* the iter(), sq_iter and __iter__
    MZ> parts.  I tremble at seeing the rest.  Why not add a method to
    MZ> dictionaries .iteritems() and do

    | for (k, v) in dict.iteritems():
    | 	pass

    MZ> (dict.iteritems() would return an an iterator to the items)

Moshe, I had exactly the same reaction and exactly the same idea.  I'm
a strong -1 on introducing new syntax for this when new methods can
handle it in a much more readable way (IMO).

Another idea would be to allow the iterator() method to take an

    for key in dict.iterator()


    for key in dict.iterator(KEYS)

and also

    for value in dict.iterator(VALUES)
    for key, value in dict.iterator(ITEMS)

One problem is that the constants KEYS, VALUES, and ITEMS would either
have to be defined some place, or you'd just use values like 0, 1, 2,
which is less readable perhaps than just having iteratoritems(),
iteratorkeys(), and iteratorvalues() methods.  Alternative spellings:

    itemsiter(), keysiter(), valsiter()
    itemsiterator(), keysiterator(), valuesiterator()
    iiterator(), kiterator(), viterator()

ad-nauseum-ly y'rs,