I have the following list:
['a', 'b', 'c']
I am exploring a way to generate all possible strings containing these characters, with the following restrictions:
- The icon may not appear multiple times (
aab, aba, abcaetc. is invalid) - a character can be excluded (for
abexample, even if it cdoes not exist; aalso valid, even if bit is cnot present)
I can use
[''.join(p) for p in permutations('abc')]
to generate all lines containing a, band c. However, I must also do
[''.join(p) for p in permutations('ab')]
[''.join(p) for p in permutations('ac')]
[''.join(p) for p in permutations('bc')]
, , , , . Python, :
def generate(vals=['a', 'b', 'c']):
res = vals
return res
, POST -, ( val) ( , ), . , , , val.
( "a", "ab", "ac", "abc", "b", "ba", 'bc' ..), , .