Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] list / array comprehensions extension

Alexander Hegerpython at 2sn.net
Thu Dec 15 17:26:50 CET 2011


Hi,in IDL/GDL, if at have an arrayx = [1,2,3]?I can simply construct a new array byy = [0,x]which would give[0,1,2,3]I know you can do this case withx[0:0] = [0]but obviously more complicated cases are conceivable, common for me, in factx=[1,2,3]y=[5,6,7]z=[0,x,4,y,8]result[0,1,2,3,4,5,6,7,8]or maybe evenz=[0,x[0:2],5]and so forth.On the other hand, if you have a function you can pass the list ofarguments to another functiondef f(*args):? g(*args)which expands the list args. ?So, would it be possible - not evenreasonable to have something similar for list and arrays, maybedictionaries, in comprehensions as well?x = [1,2,3]y = [0,*x]to obtain [0,1,2,3]or similar for listsx = (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 andobvious way I did not yet discover?-Alexander


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp