On Wednesday 27 April 2011 20:56:20 John Pinner wrote:
> On Apr 26, 4:28 am, Gnarlodious wrote:
> > I have an SQLite query that returns a list of tuples:
> >
> > [('0A',), ('1B',), ('2C',), ('3D',),...
> >
> > What is the most Pythonic way to loop through the list
> > returning a list like this?
On Apr 26, 4:28 am, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
>
> -- Gnarlie
If you want to handle
On Apr 25, 8:28 pm, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
You could unpack the 1-tuple the sam
On Tue, 26 Apr 2011 13:37:40 -0700, Ethan Furman
wrote:
: Hans Georg Schaathun wrote:
: > List comprehension is understood even by readers with no experience
: > with python.
:
: There's nothing magically understandable about a list comp -- the first
: time I saw one (which was in Python),
Hans Georg Schaathun wrote:
List comprehension is understood even by readers with no experience
with python.
There's nothing magically understandable about a list comp -- the first
time I saw one (which was in Python), I had to learn about them.
~Ethan~
--
http://mail.python.org/mailman/li
On Wed, 27 Apr 2011 04:30:01 +1000, Algis Kabaila
wrote:
: I would prefer that to using a ready made module, as it would
: be quicker than learning about the module, OTH, learning about
: a module may be useful for other problems. A standard dilema...
More importantly, list comprehensio
On Wed, Apr 27, 2011 at 5:39 AM, Mark Niemczyk wrote:
> (2) return [item[0] for item in lst] #relative
> time: 106
> (5) return [x for (x,) in lst]
> #relative time: 52
Interesting indeed. #5 will of course only work with a t
Some interesting performance comparisons, under Python 3.2. Times are
relative, and are for an initial list of tuples with 500,000 items.
(1)ans = []
#relative time: 298
for item in lst:
ans += list(item
On Tuesday 26 April 2011 22:19:08 Gnarlodious wrote:
> On Apr 25, 10:59 pm, Steven D'Aprano wrote:
> > In Python 3, map becomes lazy and returns an iterator
> > instead of a list, so you have to wrap it in a call to
> > list().
>
> Ah, thanks for that tip. Also works for outputting a tuple:
> list
On Apr 25, 10:59 pm, Steven D'Aprano wrote:
> In Python 3, map becomes lazy and returns an iterator instead of a list,
> so you have to wrap it in a call to list().
Ah, thanks for that tip. Also works for outputting a tuple:
list_of_tuples=[('0A',), ('1B',), ('2C',), ('3D',)]
#WRONG:
(x for (x,)
On Apr 26, 9:59 am, Steven D'Aprano wrote:
> On Mon, 25 Apr 2011 20:28:22 -0700, Gnarlodious wrote:
> > I have an SQLite query that returns a list of tuples:
>
> > [('0A',), ('1B',), ('2C',), ('3D',),...
>
> > What is the most Pythonic way to loop through the list returning a list
> > like this?:
On Mon, 25 Apr 2011 20:28:22 -0700, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a list
> like this?:
>
> ['0A', '1B', '2C', '3D',...
Others have point
itertools can help you do this too:
import itertools
tl = [('0A',), ('1B',), ('2C',), ('3D',)]
itertools.chain.from_iterable(tl)
list(itertools.chain.from_iterable(tl))
['0A', '1B', '2C', '3D']
Checkout http://docs.python.org/library/itertools.html#itertools.chain
for more info.
On Mon, Apr
Gnarlodious writes:
> I have an SQLite query that returns a list of tuples:
> [('0A',), ('1B',), ('2C',), ('3D',),...
> What is the most Pythonic way to loop through the list returning a
> list like this?:
> ['0A', '1B', '2C', '3D',...
Try:
tlist = [('0A',), ('1B',), ('2C',), ('3D',)]
al
On Apr 25, 2011, at 11:28 PM, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
This works for me -
On Apr 25, 9:42 pm, CM wrote:
> flat_list = [item[0] for item in returned_list]
HA! So easy. Thanks.
-- Gnarlie
--
http://mail.python.org/mailman/listinfo/python-list
>What is the most Pythonic way to loop through the list returning a
>list like this?:
here's how I'd do it:
>>> i
[(1, 'a'), (2, 'b'), (3, 'c')]
>>> for item in i:
... a+=list(item)
...
...
>>> a
[1, 'a', 2, 'b', 3, 'c']
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 25, 11:28 pm, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
>
> -- Gnarlie
For just this case,
I have an SQLite query that returns a list of tuples:
[('0A',), ('1B',), ('2C',), ('3D',),...
What is the most Pythonic way to loop through the list returning a
list like this?:
['0A', '1B', '2C', '3D',...
-- Gnarlie
--
http://mail.python.org/mailman/listinfo/python-list
19 matches
Mail list logo