# PydataSet vs list of tuples returned query result

**URL:** <https://forum.inductiveautomation.com/t/pydataset-vs-list-of-tuples-returned-query-result/10824>\
**Category:** Ignition\
**Created:** [November 25, 2015, 2:13am UTC](https://forum.inductiveautomation.com/t/pydataset-vs-list-of-tuples-returned-query-result/10824 "2015-11-25T02:13:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ella\_ramos](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ella_ramos/32/3455_2.png) [@ella\_ramos](https://forum.inductiveautomation.com/u/ella_ramos)\
**Post date:** [November 25, 2015, 2:13am UTC](https://forum.inductiveautomation.com/t/pydataset-vs-list-of-tuples-returned-query-result/10824/1 "2015-11-25T02:13:54Z")

</div>

I have this query in Python

cursor = cnx.cursor()

`cursor.execute("""
    SELECT batchdata.wafer
         , runsettings.settingname
         , runsettings.float8value
        FROM runsettings
            INNER JOIN batchdata
                ON batchdata.equipment = runsettings.equipment
                AND batchdata.wafer = runsettings.wafer
        WHERE
            runsettings.equipment = 'toolid' AND
            runsettings.runnumber = 1
        ORDER BY batchdata.wafer;
""")
wafer_groups = itertools.groupby(cursor.fetchall(), key=itertools.itemgetter(0))
lstoflst = [dict(row[1:] for row in group[1]) for group in wafer_groups]`

and the return is a list of dictionaries.

I have the same query on Ignition:

[code]qry = “”"  
SELECT batchdata.wafer  
, runsettings.settingname  
, runsettings.float8value  
FROM runsettings  
INNER JOIN batchdata  
ON batchdata.equipment = runsettings.equipment  
AND batchdata.wafer = runsettings.wafer  
WHERE  
runsettings.equipment = ‘DUV001’ AND  
runsettings.runnumber = 1  
ORDER BY batchdata.wafer;  
“”"

qrydata = system.db.runPrepQuery(qry)

wafer\_groups = itertools.groupby(qrydata, key=itemgetter(0))  
lst = []  
for group in wafer\_groups:  
dic = {}  
for row in group[1]:  
row = [i for i in row]  
dic[row[1]] = row[2]  
lst.append(dic)[/code]

Since in Ignition its returning a PyDataSet instead of list of tuples from the SELECT query, I cannot create a list of dictionary using the one liner “dict” function.

Is there anyway that i can convert the PyDataSet to a list of tuples?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 25, 2015, 4:25am UTC](https://forum.inductiveautomation.com/t/pydataset-vs-list-of-tuples-returned-query-result/10824/2 "2015-11-25T04:25:35Z")

</div>

```auto
def pds_to_tuples(pds):
	return map(lambda r: tuple([c for c in r]), pds)
```

---

<div class="post-metadata">

**Author:** ![ella\_ramos](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ella_ramos/32/3455_2.png) [@ella\_ramos](https://forum.inductiveautomation.com/u/ella_ramos)\
**Post date:** [November 25, 2015, 6:29am UTC](https://forum.inductiveautomation.com/t/pydataset-vs-list-of-tuples-returned-query-result/10824/3 "2015-11-25T06:29:32Z")

</div>

Thanks Kevin,

Works like magic.
