Hi
I am trying to shorten my code with some for loops inside of print functions, but I run into this problem:
JavaScript
x
10
10
1
List = ["######################",
2
"# #",
3
"# #",
4
"# Hello There #",
5
"# #",
6
"# #",
7
"######################"]
8
9
print(l for l in List)
10
Output:
JavaScript
1
2
1
<generator object <genexpr> at 0x000001F704B0B820>
2
is there a way to make this work without doing:
JavaScript
1
3
1
for l in List:
2
print(l)
3
Output:
JavaScript
1
8
1
######################
2
# #
3
# #
4
# Hello There #
5
# #
6
# #
7
######################
8
or do I have to stick with that?
I am sorry if this question is somewhere else, I just couldn’t find it. If you manage to find it, feel free to send a link instead of explaining it here too.
thanks in advance
Advertisement
Answer
You cannot use loop inside print()
but you can do
JavaScript
1
9
1
spam = ["######################",
2
"# #",
3
"# #",
4
"# Hello There #",
5
"# #",
6
"# #",
7
"######################"]
8
print('n'.join(spam))
9