escape sequences in list comprehensions

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Nov 12 12:47:09 EST 2004


kartik wrote:
> Escape sequences don't seem to work in strings within list comprehensions:
> 
>>>>print ['%s\n' %i for i in [1,2,3]]
> 
> ['1\n', '2\n', '3\n']
> 
> What am I missing?

Other have answered to this question.

Just try this instead :
   print "\n".join(["%d" % i for i in [1,2,3]])

> Thank you.
HTH




More information about the Python-list mailing list