Python Nested tuples to list

dobbs

I have a mysql query that runs and selects all of the Id's that match the select statement:

first_seen_select = "SELECT Id FROM domains_archive WHERE current_epoch = " + current_epoch + " AND first_seen IS NULL"
cur.execute(first_seen_select)

The output of cur.fetchall() is

((1,), (2,), (3,), (4,), (5,), (6,), (7,))

How do i extract these nested tuple Id #'s and convert them into a single list that i can iterate over?

If i run the following i get:

>>> bleh = cur.fetchall()
>>> for i in bleh:
...   print(i)
... 
(1,)
(2,)
(3,)
(4,)
(5,)
(6,)
(7,)
tuxtimo

you can use a simple list comprehension:

[y for x in l for y in x]

Or with more meaningful variable names:

[item for sublist in l for item in sublist]

this will result in:

In [8]: l = ((1,), (2,), (3,), (4,), (5,), (6,), (7,))

In [9]: [y for x in l for y in x]
Out[9]: [1, 2, 3, 4, 5, 6, 7]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python convert list of nested tuples to list of tuples

From Dev

Python convert a list of nested tuples into a dict

From Dev

How to convert a two nested list of lists into a nested list of tuples in Python?

From Dev

How to convert nested list of lists into a list of tuples in python 3.3?

From Dev

How to unpack tuples in nested list?

From Dev

How to remove tuples nested on a list?

From Dev

How to unpack tuples in nested list?

From Dev

Convert from tuple of tuples to nested tuples in Python

From Dev

python unpacking list of tuples

From Dev

Ordering a list of tuples in python

From Dev

Merging list of tuples in python

From Dev

Python List of tuples in Scala

From Dev

max in a list of tuples (Python)

From Dev

Merging list of tuples in python

From Dev

comparing a list of tuples python

From Dev

tuples and list arrangements in python

From Dev

Dictionary with list of tuples Python

From Dev

Nested List of Lists to Single List of tuples

From Dev

Filtering nested lists of Tuples in Python

From Dev

Convert Nested dictionaries to tuples python

From Dev

compare string against tuples in list of tuples - python

From Dev

compare string against tuples in list of tuples - python

From Dev

Python: from list of tuples to dictionary of tuples

From Dev

Changing nested list of numbers to nested list o tuples

From Dev

Creating a nested dictionary from a list of tuples

From Dev

How to round every float in a nested list of tuples

From Dev

Unpacking nested tuples using list comprehension

From Dev

Split long list of tuples into nested lists

From Dev

sum the count of duplicate in a nested list of tuples

Related Related

HotTag

Archive