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
Post a Comment