I am using the exrex
package to generate a list of all permutations for a regex. But, I have several regexes and want to create a set of all permutations (without duplicates). So, given:
from exrex import generate
my_regexs=('a|b','a|c')
expansions=map(generate,my_regexs)
Perhaps I don't even need map
or the intermediate variable expansions
for this - not sure. Now, how do I get a sorted list from these:
# Create a set from all of the expansions (e.g., let's store in myset, for clarity)
# in order to merge duplicates
myset=... # Results in myset containing {'a','c','b'} - hash order
sorted_list=sorted(myset) # Finally, we get ['a','b','c']
Thanks for any help with this and I bet there is a simple one-liner with a list comprehension that can do this.
Note: We are dealing with a map
object containing multiple generators (i.e., a sequenced container of multiple generators, not a list
of lists!)
Update: I thought I made the inputs and outputs clear:
Input: ('a|b','a|c') # Two reg-exs, results in all-permutations: ['a','b','a','c']
Output: ['a','b','c'] # Eliminating duplicates, we get the output presented