I am processing the Cartesian product of a list of entities.
For e.g. a_list = ['a','b']
The expected output is:
"a";"a"&"a";"b"&"b";"a"&"b";"b"
Each entity in the entity pair is separated by semicolon ";" and each enitity pair is separated by "&".
I used following nested for loop to achieve the output.
entity_set = ['a','b']
domain_text = ''
count = 0
for entity1 in entity_set:
for entity2 in entity_set:
count += 1
domain_text += '"' + entity1 + '"' + ';' + '"' + entity2 + '"'
if count < (len(entity_set)*len(entity_set)):
domain_text += '&'
print domain_text
However, the process gets too slow as the size of a_list increases to thousands of entities.
Is there any elegant solutions that can be used alternatively?