【发布时间】:2019-02-09 13:10:37
【问题描述】:
我想找到一个 str 的所有可能分区,没有空 strs 并且必须包含任何 char(不应包含原始 str)
例如:
s = '1234'
partitions(s) # -> [['1', '2', '3', '4'], ['1', '2', '34'], ['1', '23', '4']
# ['12', '3', '4'], ['12', '34'], ['1', '234'], ['123', '4']]
# should not contain ['1234']
编辑:可以是任何顺序
为什么我的问题不是重复的:
我不想要以下排列:
from itertools import permutations
s = '1234'
permutations(s) # returns ['1', '2', '3', '4'], ['1', '2', '4', '3']...
但我希望将字符串分割成多个长度(请查看第一个代码)
谢谢!
【问题讨论】:
-
您好!您是否考虑过使用 for 循环? (您是否尝试过解决问题,即)。
-
相关但不完整的分区:stackoverflow.com/a/31581790/2573061
标签: python arrays string python-3.x