RosettaCodeData/Task/Sierpinski-carpet/Python/sierpinski-carpet-2.py
2023-07-01 13:44:08 -04:00

9 lines
268 B
Python

def sierpinski_carpet(n):
carpet = ["#"]
for i in xrange(n):
carpet = [x + x + x for x in carpet] + \
[x + x.replace("#"," ") + x for x in carpet] + \
[x + x + x for x in carpet]
return "\n".join(carpet)
print sierpinski_carpet(3)