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

noreply@sourceforge.net noreply@sourceforge.net
Sun, 13 Aug 2000 19:36:02 -0700


Patch #101178 has been updated. 

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

Follow-Ups:

Date: 2000-Aug-13 19: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-13 19: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.
-------------------------------------------------------

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

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