Why I think range is a wart.
ruud de rooij
* at spam.ruud.org
Wed Mar 13 12:00:55 EST 2002
Max M <maxm at mxm.dk> writes:
> ruud de rooij wrote:
>
> > perhaps lists should support .keys() and .items() for those operations
> > (analogous to dictionaries).
>
> Yes if that doesn't conflict with anything it would be a very nice way
> to solve 99% of the cases where I typically use the range function:
>
> theList = ['item1', 'item2', 'item3']
> subList = ['item4', 'item5', 'item6']
> for i, item in theList.items():
> print item, sublist[i]
>
> But it would not help much in list comprehensions unless they are rewritten:
>
> newList = [(theList[i], sublist[i]) for i in range(len(theList))]
assuming .items() would work for lists, you could also write that as
follows (or is that what you meant with "unless they are rewritten"?):
[ (item, sublist[i]) for (item, i) in thelist.items() ]
- ruud
--
ruud de rooij | *@spam.ruud.org | http://ruud.org
More information about the Python-list
mailing list