- 论坛徽章:
- 26
|
回复 1# 漠北病树
用户输入字符不加引号
# 比如用户输入:
' [s, d,j], [1, 2,3], [ x, y],[ A, B,C ] '
输出下面结果:
s 1 x A
s 1 x B
s 1 x C
s 1 y A
s 1 y B
s 1 y C
s 2 x A
s 2 x B
s 2 x C
s 2 y A
s 2 y B
s 2 y C
s 3 x A
s 3 x B
...
等等 。- #!/usr/bin/python2
- # -*- coding: utf-8 -*-
- # 用户输入字符不加引号
- # 比如用户输入:
- USR = ' [s, d,j], [1, 2,3], [ x, y],[ A, B,C ] '
- # USR = raw_input('input:\n')
- def Make(STR):
- STR = STR.replace(' ', '')[1:-1]
- LST = [i.split(',') for i in STR.split('],[')]
- RES = [[]]
- for i in LST:
- RES = [r + [j] for r in RES for j in i]
- return RES
- for i in Make(USR): print ' '.join(i)
复制代码 |
|