Question

I've data like this. x is a list below.

['197056942', '91004902', ['104608942', '95134582'], '91967062']

Expected result should be: 197056942|91004902|104608942|91967062 197056942|91004902|95134582|91967062

I've tried to use zip but unable to get the right result. Its truncating the data.

zip(*x) [('1', '9', '104608942', '9'), ('9', '1', '95134582', '1')]

Was it helpful?

Solution

I tried to solved your problem. It was very difficult than I thought. Here is my Python code.

input = ['1','2','3','4',['5','6','7'],'8','9',['10','11'],'12']
tmp = [[]]
for i in input:
    if isinstance(i, list):
        tmp = [j+[k] for j in tmp for k in i]
    else:
        tmp = [j+[i] for j in tmp]

output = ["|".join(i) for i in tmp]

output:

>>> output
['1|2|3|4|5|8|9|10|12',
 '1|2|3|4|5|8|9|11|12',
 '1|2|3|4|6|8|9|10|12',
 '1|2|3|4|6|8|9|11|12',
 '1|2|3|4|7|8|9|10|12',
 '1|2|3|4|7|8|9|11|12']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top