what could be the code if I want to write ta python code that prints all possible strings that can be formed from a given string. for example. if my in put is -“AB” it should return -[“A”,”B”,”AB”,”BA”] all values of the list in output should be different.
Advertisement
Answer
Take a look at itertools.combinations:
itertools.combinations(iterable, r)
Return r length subsequences of elements from the input iterable.
Combinations are emitted in lexicographic sort order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order.