Hi I found the below function on some website somewhere and just have a couple of questions. The function returns a diamond of n lines made from asterisks.
- Is that a concatenated for loop? Is that a thing you can do?
- What is going on in that f-string? How does
'':*<{line*2+1}
work?
def diamond(n):
result = ""
for line in list(range(n)) + list(reversed(range(n-1))):
result += f"{'': <{n - line - 1}} {'':*<{line*2+1}}\n"
return result