I have a list containing a tuples and long integers the list looks like this:
table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)]
How do i convert the table to look like a formal list?
so the output would be:
table = ['1','1','1','2','2','2','3','3']
For information purposes the data was obtained from a mysql database.
>>> table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)]
>>> [int(e[0]) for e in table]
[1, 1, 1, 2, 2, 2, 3, 3]
>>> [str(e[0]) for e in table]
['1', '1', '1', '2', '2', '2', '3', '3']
With itertools
import itertools
>>> x=[(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)]
>>>
>>> list(itertools.chain(*x))
[1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L]
>>>
>>> map(str,itertools.chain(*x))
['1', '1', '1', '2', '2', '2', '3', '3']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With