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

noreply@sourceforge.net noreply@sourceforge.net
Tue, 15 Aug 2000 11:04:54 -0700

Patch #101178 has been updated. 

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


Date: 2000-Aug-13 19:23
By: nowonder

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

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 11:04
By: tim_one

Assigned to Guido for Pronouncement.

For more info, visit: