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.
Unlock 108 remaining solutions by signing in and submitting your own entry
#109 David Burns / @AutomatedTester - Score: 146 - 01/28/11 @ 15: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