python - Flattened out a mixed type of list -


i have mixed list looked this:

[('1cfv',), 'nonrbp', [0.00325071141379, 0.278046326931, 0.291350892759]] 

it created command:

in [12]: l1 =  [0.00325071141379, 0.278046326931, 0.291350892759]  in [13]: t1 = ('1cfv',)                                                            in [14]: s1 = "nonrbp"  in [15]: mixl = [t1,s1,l1]  in [16]: mixl 

is there way convert into:

   ['1cfv', 'nonrbp', 0.00325071141379, 0.278046326931, 0.291350892759] 

i tried this, flattened out string 'nonrbp' not want:

 [item sublist in mixl item in sublist] 

>>> final = [] >>> = [('1cfv',), 'nonrbp', [0.00325071141379, 0.278046326931, 0.291350892759]] >>> in a: ...   if hasattr(i, '__iter__'): ...     j in i: ...       final.append(j) ...   else: ...     final.append(i) ...  >>> print final ['1cfv', 'nonrbp', 0.00325071141379, 0.27804632693100001, 0.291350892759] 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -