假设行列长度都为5,但字典长度及值为4。当值的长度小于假设值时,就重复值,当字典的长度小于假设值时,也是重复字典,直到满足条件为止。如下图所示
就不断叠加行和列,然后取一定限制,献上代码:
def print_pattern(pattern, limit):
rows = []
for r in range(len(pattern)):
col = pattern[r]
while len(col) < limit:
col += pattern[r]
else:
col = col[:limit]
rows.append(col)
while len(rows) < limit:
rows += rows
else:
rows = rows[:limit]
print('\n'.join(rows))
patterns = {0: '0123', 1: '1230', 2: '2301', 3: '3012'}
print_pattern(patterns, 5)
print()
patterns = {0: '@#$', 1: '#$@', 2: '$@#'}
print_pattern(patterns, 5)