Python - How to transform a list of tuple to a tuple -
this question has answer here:
i retrieved data sql query and
i have list of tuple like:
[(34.2424,), (-64.2344,) (76.3534,), (45.2344,)] and have string (34.2424, -64.2344, 76.3534, 45.2344,)
does function exist can that?
notice ',' @ end of each tuple... have difficulty rid of it
if you're using python 2.x, can use:
>>> = [(34.2424, -64.2344, 76.3534, 45.2344)] >>> print ' '.join(map(str, a[0])) '34.2424 -64.2344 76.3534 45.2344' in python 3.x, or python 2.x from __future__ import print_function, can use:
>>> print(*a[0]) 34.2424 -64.2344 76.3534 45.2344 you seem have updated format of input data, so:
first element each tuple...
>>> = [(34.2424,), (-64.2344,), (76.3534,), (45.2344,)] >>> print ' '.join(str(el[0]) el in a) 34.2424 -64.2344 76.3534 45.2344 more 1 element in each tuple...
>>> itertools import chain >>> print(*chain.from_iterable(a)) 34.2424 -64.2344 76.3534 45.2344 however, seem want tuple...
>>> tuple(chain.from_iterable(a)) (34.2424, -64.2344, 76.3534, 45.2344) which can use str on make str if wanted...
Comments
Post a Comment