On Apr 26, 4:28 am, Gnarlodious gnarlodi...@gmail.com 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
On Wednesday 27 April 2011 20:56:20 John Pinner wrote:
On Apr 26, 4:28 am, Gnarlodious gnarlodi...@gmail.com 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
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 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:
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 +=
On Wed, Apr 27, 2011 at 5:39 AM, Mark Niemczyk praham...@gmail.com 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
On Wed, 27 Apr 2011 04:30:01 +1000, Algis Kabaila
akaba...@pcug.org.au 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
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~
--
On Tue, 26 Apr 2011 13:37:40 -0700, Ethan Furman
et...@stoneleaf.us 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
On Apr 25, 8:28 pm, Gnarlodious gnarlodi...@gmail.com 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
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
On Apr 25, 11:28 pm, Gnarlodious gnarlodi...@gmail.com 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
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, 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
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 -
result
Gnarlodious gnarlodi...@gmail.com 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',),
itertools can help you do this too:
import itertools
tl = [('0A',), ('1B',), ('2C',), ('3D',)]
itertools.chain.from_iterable(tl)
itertools.chain object at 0x11f7ad0
list(itertools.chain.from_iterable(tl))
['0A', '1B', '2C', '3D']
Checkout
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 pointed you
On Apr 26, 9:59 am, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info 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
19 matches
Mail list logo