Assume there is a list demo_list
:
[u'demo', u'trial']
Using for loop to print every element with '\n':
for i in demo_list:
print(i)
it works as expected:
demo
trial
However, I would like to use the bracket to express this loop:
print([ i for i in demo_list])
But it directly prints the whole list in one line:
[u'demo', u'trial']
For the expression [print(i) for i in demo_list]
, it says SyntaxError: invalid syntax
.
My question is:
- How to put every element in new lines using the bracket?
- What is wrong with the expression
[print(i) for i in demo_list]
?
Any help is appreciated.