-2

I query data from database from one colomn and I want use them but I do know how to extract them.

[(725696042,), (706284799,), (705263536,), (706705005,)]

I what to get the results like this

725696042, 706284799, 705263536, 706705005

Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
  • What have you tried so far to achieve this? – Shnick May 22 '19 at 07:58
  • I guess the query itself could be modified to get your expected result in the first place – sjsam May 22 '19 at 07:59
  • You need from list of tuples to tuple. Try this : `tuple(i[0] for i in list_)` – Arkistarvh Kltzuonstev May 22 '19 at 08:00
  • You should first learn the basic of the prog lang that you will use (you ll find directly the answer), then you must give it some tries before calling for help.. – Rafik May 22 '19 at 08:00
  • Possible duplicate of [How to make a flat list out of list of lists](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists) – vezunchik May 22 '19 at 08:03

2 Answers2

0

Not sure I get you right but this is what i understood:

a = [(725696042,), (706284799,), (705263536,), (706705005,)]

a[0] = (725696042,)
a[0][0] = 725696042
a[1] = (706284799,)
a[1][0] = 706284799
....

This way you can access your elements to extract values

  • Instead of going thru the pain of parsing the data, the op may adjust his query to get their expected result directly. In that perspective, the question looks like an [XY Problem](http://xyproblem.info/) – sjsam May 22 '19 at 08:04
0

I believe this is what you're looking for.

list1 = [(725696042,), (706284799,), (705263536,), (706705005,)]
list2 = []
for i in list1:
    list2.append(i[0])

print(list2)

Output:

[725696042, 706284799, 705263536, 706705005]
jchua
  • 354
  • 1
  • 4
  • 15