I have 4 arrays like this:
temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
I want output:
adfg
aefg
afg
bdfg
befg
bfg
cdfg
cefg
cfg
and I solved it using following:
temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
for list_1 in temp1:
for list_2 in temp2:
for list_3 in temp3:
for list_4 in temp4:
temp_list = ''
if list_1: temp_list += list_1
if list_2: temp_list += list_2
if list_3: temp_list += list_3
if list_4: temp_list += list_4
print "%s " %(temp_list)
but I think my code isn't efficient.
How to make good algorithm and make it efficient.
and how about if temp3 is null for example :
temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = []
temp4 = ['g']