这个漂亮的脚本生成给定 set 的所有 4 个字符排列s
,并将它们打印在新行上。
import itertools
s = ('7', '8', '-')
l = itertools.product(s, repeat=4)
print(*l, sep='\n')
样本输出:
...
('9', '-', '7', '8')
('9', '-', '7', '9')
('9', '-', '8', '7')
('9', '-', '8', '8')
('9', '-', '8', '9')
...
我不知道如何删除所有单引号、逗号和左/右括号。
期望的输出:
...
9-78
9-79
9-87
9-88
9-89
...
尝试添加:
c = []
for i in l:
i = i.replace(",", '')
c.append(i)
print(*c, sep='\n')
错误: AttributeError: 'tuple' object has no attribute 'replace'
还尝试过:我似乎无法找到将print(' '.join())
逻辑放在哪里。