Why I think range is a wart.
Max M
maxm at mxm.dk
Wed Mar 13 11:48:09 EST 2002
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))]
regards Max M
More information about the Python-list
mailing list