-1

I have a list as:

mylist = [['469536.18999', '6334694.44001', '-9999.0'], '-9999.0', '-9999.0', '-9999.0', '-9999.0']

i wish to unlist as:

['469536.18999', '6334694.44001', '-9999.0', '-9999.0', '-9999.0', '-9999.0', '-9999.0']

i used different approaches but always i got the wrong result:

from itertools import chain
print list(chain.from_iterable(mylist))
['469536.18999', '6334694.44001', '-9999.0', '-', '9', '9', '9', '9', '.', '0', '-', '9', '9', '9', '9', '.', '0', '-', '9', '9', '9', '9', '.', '0', '-', '9', '9', '9', '9', '.', '0']

sum(mylist, [])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
Gianni Spear
  • 7,033
  • 22
  • 82
  • 131

1 Answers1

1

Try this code

c=[['469536.18999', '6334694.44001', '-9999.0'], '-9999.0', '-9999.0', '-9999.0', '-9999.0']

x=[]
for i in range(len(c)):
    if 'list' in str(type(c[i])):
        for j in range(len(c[i])):
            x.append(c[i][j])
    else :
        x.append(c[i])
print x

Output: ['469536.18999', '6334694.44001', '-9999.0', '-9999.0', '-9999.0', '-9999.0', '-9999.0']

Anandhakumar R
  • 371
  • 1
  • 3
  • 17