- Nov 29, 2005
- 2,411
- 0
- 0
So, I've pretty much got this issue: http://stackoverflow.com/questions/...st-from-sqlite-in-python-not-a-list-of-tuples
i.e.
Fetchall is returning a list of tuples, not just a list of the relevant returned column. Right now, I have some ridiculously hack-y and non-pythonic way of converting the list of tuples to just an array/list/whatever (sorry, I'm more used to C++ forgive the abuse of notation), but....
Now, these result sets are relatively tiny (anywhere from, say, 50 to at most a few hundred) so there's absolutely not real reason why I can't continue doing this, but it makes the code ugly, and at some point, I should probably learn how to do it "right".
Sooooo, if you want to iterate across the list of tuples (but obviously only accessing the first relevant element of each tuple), or more aptly, be able to send the list to other functions expecting just an array (i.e. "min" or the like, for example), what's the pythonic way of doing that? Things like min, max, etc. bark at me when they get the normal list of tuples, so how do I send them just the relevant tuple members?
Simple enough, right? Thanks!
i.e.
Code:
e.g cursor.fetchall() returns [(u'one',), (u'two',), (u'three',)]
from this, how do i get the simple list [u'one', u'two', u'three']?
Fetchall is returning a list of tuples, not just a list of the relevant returned column. Right now, I have some ridiculously hack-y and non-pythonic way of converting the list of tuples to just an array/list/whatever (sorry, I'm more used to C++ forgive the abuse of notation), but....
Now, these result sets are relatively tiny (anywhere from, say, 50 to at most a few hundred) so there's absolutely not real reason why I can't continue doing this, but it makes the code ugly, and at some point, I should probably learn how to do it "right".
Sooooo, if you want to iterate across the list of tuples (but obviously only accessing the first relevant element of each tuple), or more aptly, be able to send the list to other functions expecting just an array (i.e. "min" or the like, for example), what's the pythonic way of doing that? Things like min, max, etc. bark at me when they get the normal list of tuples, so how do I send them just the relevant tuple members?
Simple enough, right? Thanks!
Last edited: