[Python-ideas] fancy indexing (original) (raw)
Chris Rebert pyideas at rebertia.com
Wed Jul 21 02:24:41 CEST 2010
- Previous message: [Python-ideas] fancy indexing
- Next message: [Python-ideas] fancy indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jul 20, 2010 at 4:43 PM, Bruce Leban <bruce at leapyear.org> wrote:
x = a[[y]] would be approximately equivalent to x = [a[i] for i in y]
You realize that syntax /already/ has a valid meaning in Python, right? Namely, using a single-element list as a subscript:
class Foo(object): ... def getitem(self, index): ... print "Subscript:", index ... a = Foo() y = 42 x = a[[y]] Subscript: [42] # hey, whaddya know!
Making this syntax do something else would lead to some surprising inconsistencies to say the least; albeit I don't know how common it is to use lists as subscripts.
Cheers, Chris
- Previous message: [Python-ideas] fancy indexing
- Next message: [Python-ideas] fancy indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]