Python - convert list of tuples to a list of int -



Python - convert list of tuples to a list of int -

i have

x = [[1], [2, 3], [1, (3, 5)], [(3, 9), 7, 5]]

and want

x = [[1], [2, 3], [1, 3, 5], [3, 9, 7, 5]]

how can this?

you accomplish through series of loops.

>>> x = [[1], [2, 3], [1, (3, 5)], [(3, 9), 7, 5]] >>> l = [] >>> in x: m = [] j in i: if isinstance(j, tuple): m.extend(j) else: m.append(j) l.append(m) >>> l [[1], [2, 3], [1, 3, 5], [3, 9, 7, 5]]

python list tuples

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -