[Patches] [Patch #101178] add items() method to listobject

noreply@sourceforge.net noreply@sourceforge.net
Thu, 17 Aug 2000 12:02:15 -0700


Patch #101178 has been updated. 

Project: 
Category: core (C code)
Status: Rejected
Summary: add items() method to listobject

Follow-Ups:

Date: 2000-Aug-14 02:23
By: nowonder

Comment:
This patch adds a .items() method to the list object. .items() returns a list with of tuples. E.g.:

for index, value in ["a", "b", "c"].items():
  print index, ":", value

will print:

0: a
1: b
2: c

I think this is an easy way to achieve looping over index AND elements in parallel. Semantically the following two expressions should be equivalent:

for index, value in zip(range(len(mylist)), mylist):
for index, value in mylist.items():

In opposition to patch #110138 I would call this:
"Adding syntactic sugar without adding syntax (or sugar<wink>):"
-------------------------------------------------------

Date: 2000-Aug-14 02:36
By: nowonder

Comment:
just two comments:

strings (and maybe tuples) could also support .items().

There could be a function PySequence_Items in abstract.c.

BTW: test case and documentation lacking. If this is considered to be a Good Idea(tm), I'll happily supply them.
-------------------------------------------------------

Date: 2000-Aug-15 18:04
By: tim_one

Comment:
Assigned to Guido for Pronouncement.
-------------------------------------------------------

Date: 2000-Aug-15 20:11
By: nowonder

Comment:
Note: tim (I believe) said that items() would mean there would have to be key() and value(), too.

I disagree. index() and value(), maybe. But key() does not make any sense for a list.

I see the issue with execution speed and memory overhead though, so as I am not really opposed to 'for index indexing value in sequence' I would be okay with that. In any case it would be nice to have some way to express this.
-------------------------------------------------------

Date: 2000-Aug-17 19:02
By: gvanrossum

Comment:
I don't like this idea at all. There is not enough similarity between dicts and lists to do this.
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=101178&group_id=5470