expand a list comprehension (python)
Please show your way to convert a list comprehension in python to an ordinary for-loop expression!
Start file
print [x**2 for x in xrange(10)]
End file
tmp = []
for x in xrange(10):
tmp.append(x**2)
print tmp
View Diff
1c1,4 < print [x**2 for x in xrange(10)] --- > tmp = [] > for x in xrange(10): > tmp.append(x**2) > print tmp
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
#64 Matthieu Honel / @ocus - Score: 66 - 01/28/11 @ 07:31
itmp = []<CR><Esc>vf "axxvf "bx$r:otmp.append(<Esc>"bpi)<CR><Esc>"apAtmp<Esc>k<<i <Esc>ZZ
0 comments
#65 Helder Inacio / @inaciohj - Score: 67 - 02/02/11 @ 19:32
dwo<Esc>pkxdt]<Esc>o<Esc>pA:<Esc>khdi[jo<C-U><Esc>4a <Esc>atmp.apped<C-H>nd()<Esc>Pjatmp<Esc>ggItmp = <Esc>:wq<CR>
0 comments
#66 Torben Rasmussen / @rasmustorben - Score: 67 - 08/16/11 @ 09:34
witmp<NL><Esc>..lv$hhdkJa= <Esc>kp0fxi.append(<Esc>Ea)<Del><NL><Esc>A:<Esc>k4I <Esc>ddpggddGpkddggPZZ
0 comments
#67 Dmitry Teslenko / @krab_mozga - Score: 69 - 02/02/11 @ 01:43
witmp<Esc>yiwwpa.append(<Esc>/2<CR>a)<Esc>?[<CR>i<Esc>pa = <Esc>?t<CR>d$O<Esc>pdn<Esc>o<Esc>pa:<Esc>?f<CR>d^o<Esc>px^4PZZ
0 comments
#68 Jon Bettinger / @jonbettinger - Score: 70 - 01/30/11 @ 18:35
ffi<CR><Esc>3XXx$r:<CR>o tmp.append(x**2)<CR>print tmp<Esc>^XXXX:q<BS>1<CR>Ditmp = []<Esc>:wq<CR>
0 comments
#69 stefan otte / @stefanotte - Score: 70 - 01/30/12 @ 05:39
itmp <Esc>ww.i<CR><Esc>veE<Right>xpuo<Esc>p<Up>A<BS>:<Esc><Down>I tmp.append(<Del><Esc>A<BS>u<BS>)<Esc>ggwi= []<CR><Esc>dd<Down>p:wq<CR>
0 comments
#70 Arto Vuori / @dhpe - Score: 70 - 09/01/12 @ 09:50
Itmp = []<CR><Esc>kywjfxPi.append(<Del><Esc>f r)o<Esc>p<Esc>xkdiwjPa <Esc>kffdf)O<Esc>pa:<Esc>jxF[x3i <Esc>ZZ
0 comments
#71 Vernon Thommeret / @synotic - Score: 72 - 01/30/11 @ 07:38
ffdf)o<Esc>pkFx4xjo tmp.append(<Esc>pa)<CR>p<BS><BS><BS><BS><BS>print tmp<Esc>ggciwtmp =<Esc>3lxj$a:<Esc>ZZ
0 comments
#72 Christopher Brew / @Seph1rothVII - Score: 72 - 01/10/12 @ 16:41
dWo<Esc>pi<Right>tmp<Esc>bywggP<Right>i<CR> <Esc><Right>puui<CR> <Esc>pi<Right>.append<Esc><Right>r(W<Left>r)<Right>d$<Up>i<Right> = []<CR><Esc>pr:ZZ
0 comments
#73 Pasha Klets / @p01nt - Score: 73 - 01/28/11 @ 07:27
dwo<Esc>patmp<Esc><Left><Left>ywO<Esc>4i <Esc>pa.appent<BS>d()<Esc><Up>$x^p<Left>2xO<Esc>p^itmp = <Esc><Down>^3dw:<Esc>^$a:<Esc><Down>Px:wq<CR>
0 comments
#74 Franco Lazzarino / @flazz - Score: 75 - 01/28/11 @ 16:51
ea tmp =<Esc>bywPi<CR><Esc>kddp<Esc>Otmp.append()<Esc>kdi]<Esc>o<Esc>pa:<Esc>0d/for<CR>/(n<BS><CR>P<Esc>ujP<Esc>I <Esc>f xZZ
0 comments
#75 grizzancs / @grizzancs - Score: 75 - 01/31/11 @ 04:13
Ctmp = []<CR>for x in xrange(10):<CR>tmp.append(x**2)<Esc><<i <Esc>o<BS><BS><BS><BS>print tmp<Esc>:wq<CR>
0 comments
#76 Solomon White / @rubysolo - Score: 79 - 01/28/11 @ 08:58
/f<CR>hs<CR><Esc>$s:<Esc>kddp<Esc>els<CR><Esc>kddp<Esc>ks tmp.append(<Esc>A)<Esc>ja tmep<BS><BS>p<Esc>ggOtmp = []<Esc>jnd0<Esc>:wq<CR>
0 comments
#77 Reza Lotun / @rlotun - Score: 104 - 01/30/11 @ 10:32
wwwwwv$hhlda<CR><BS><BS><Esc>pxkVdpxxxxxxxi tmp.append(<Esc>$a<BS>)<Esc>ka:<Esc>ja<Esc>0Gggi<CR><Esc>ktmp<Esc>x<Esc>itmp = []<Esc>G$a<CR><BS><BS><BS><BS>print tmp<Esc>:wq<CR>
0 comments
#78 Ilya Grigorik / @igrigorik - Score: 141 - 01/31/11 @ 16:43
i<CR><Up>tmp = []<Down><Esc>ddi<Esc>ofor x in xrange(10):<CR> tmp.append(x**2)<CR>print tmp<Esc>u:set paste<CR>i<Esc>ofor x in xrange(10):<CR> tmp.append(x**2)<CR>print tmp<Esc>:wq<CR>
0 comments
#79 David Burns / @AutomatedTester - Score: 146 - 01/28/11 @ 07:17
itmp = []<CR><Esc><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right>v<Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right>x<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>pu<Left>o<Up><CR><Up><Esc>pi<Right>:<Down><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><CR><Up><Tab><BS> tmp.append(<Esc><Down><Right>v<Right><Right><Right>x<Up>pi<Right>)<Down><BS><BS><BS>tmp<Esc><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>dw<Down>dd:wq<CR>
0 comments
VimGolf