[Python-ideas] list / array comprehensions extension
ubershmekel at gmail.com
Thu Dec 15 18:30:57 CET 2011
On Thu, Dec 15, 2011 at 6:26 PM, Alexander Heger <python at 2sn.net> wrote:
> in IDL/GDL, if at have an array
> x = [1,2,3]
> ?I can simply construct a new array by
> y = [0,x]
> which would give
> I know you can do this case with
> x[0:0] = 
> but obviously more complicated cases are conceivable, common for me, in
> or maybe even
> and so forth.
> On the other hand, if you have a function you can pass the list of
> arguments to another function
> def f(*args):
> ? g(*args)
> which expands the list args. ?So, would it be possible - not even
> reasonable to have something similar for list and arrays, maybe
> dictionaries, in comprehensions as well?
> x = [1,2,3]
> y = [0,*x]
> to obtain [0,1,2,3]
> or similar for lists
> x = (1,2,3)
> y = (0,*x)
> to obtain (0,1,2,3)
> (for dictionaries, which are not sorted, the extend function seems fine)
> Or is there a way of doing this that in a similarly compact and
> obvious way I did not yet discover?
> Python-ideas mailing list
> Python-ideas at python.org
This is the wrong list for such a question. Python-ideas is a place to
discuss ideas for the python language itself. You can use
stackoverflow.comin the future.
In any case, is this good enough?
>>> x = [1,2,3]
>>> y =  + x
[0, 1, 2, 3]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas