[Python-ideas] fancy indexing (original) (raw)
Bruce Leban bruce at leapyear.org
Wed Jul 21 01:43:13 CEST 2010
- Previous message: [Python-ideas] fancy indexing
- Next message: [Python-ideas] fancy indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
x = a[[y]]
would be approximately equivalent to x = [a[i] for i in y] and a[[x]] = y would be approximately equivalent to for (i,j) in zip(x,y): a[i] = j except that zip throws away excess values in the longer sequence and I think [[..]] would throw an exception.
--- Bruce http://www.vroospeak.com http://google-gruyere.appspot.com
On Tue, Jul 20, 2010 at 3:51 PM, Mathias Panzenböck < grosser.meister.morti at gmx.net> wrote:
I'm not sure what this is about but do you mean something like this? >>> l=[1,2,3,4] >>> l[1:2] = ['a','b'] >>> l [1, 'a', 'b', 3, 4]
On 07/20/2010 09:17 PM, Bruce Leban wrote: [changing the subject; was: 'where' statement in Python?]
I think this is an interesting idea (whether worth adding is a different question). I think it would be confusing that a[x] = (y,z) does something entirely different when x is 1 or (1,2). If python were to add something like this, I think perhaps a different syntax should be considered: a[[x]] = y y = a[[x]] which call setitems and getitems respectively. This makes it clear that something different is going on and eliminates the ambiguity for dicts.
Python-ideas mailing list Python-ideas at python.org http://mail.python.org/mailman/listinfo/python-ideas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100720/cc40fac4/attachment.html>
- Previous message: [Python-ideas] fancy indexing
- Next message: [Python-ideas] fancy indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]