I am trying remove brackets from the nested array. Thank you for helping me in advance..
this is input data
{
"th":[ [ "aa"],["bb"]]
}
expected output is
{
"th":["aa","bb"]
}
I am trying remove brackets from the nested array. Thank you for helping me in advance..
this is input data
{
"th":[ [ "aa"],["bb"]]
}
expected output is
{
"th":["aa","bb"]
}
Maybe not elegant but simple:
data={
"th":[ [ "aa"],["bb"]]
}
data["th_mod"]=[element[0] for element in data["th"]]
data
Gives
{'th': [['aa'], ['bb']], 'th_mod': ['aa', 'bb']}
you can use itertools.chain.from_iterable
to accomplish this:
import itertools
data["th_mod"] = itertools.chain.from_iterable(data["th"])
this can be done also using itertools.chain
equivalent to this code:
import itertools
data["th_mod"] = itertools.chain(*data["th"])
here is the output:
>>> data
{"th":[["aa"],["bb"]],"th_mod":["aa","bb"]}