Ben Finney wrote:
Paul Rubin http://[EMAIL PROTECTED] writes:
I don't like square-bracket listcomps because they leak the index
variables to the outside.
According to PEP 289 URL:http://www.python.org/dev/peps/pep-0289,
this is an acknowledged wart that will be fixed in Python 3.0.
Has
James Fassett [EMAIL PROTECTED] writes:
tuple_list = (
('John', 'Doe'),
('Mark', 'Mason'),
('Jeff', 'Stevens'),
('Bat', 'Man')
)
# the final functional way
[result_list, _] = zip(*tuple_list)
That's really ugly IMO. I'd use:
result_list = list(x for (x,y) in
Paul Rubin http://[EMAIL PROTECTED] writes:
I don't like square-bracket listcomps because they leak the index
variables to the outside.
According to PEP 289 URL:http://www.python.org/dev/peps/pep-0289,
this is an acknowledged wart that will be fixed in Python 3.0.
--
\“None can love
On Jul 12, 12:18 am, George Sakkis [EMAIL PROTECTED] wrote:
It relies on positional arguments, tuple unpacking and
the signature of zip(),
It moreso relies on the fact that:
t1 = (0,1,2,3)
t2 = (7,6,5,4)
[t1, t2] == zip(*zip(t1, t2))
True
This is mathematically true given the definition of
On 14 juil, 11:51, James Fassett [EMAIL PROTECTED] wrote:
On Jul 12, 12:18 am, George Sakkis [EMAIL PROTECTED] wrote:
It relies on positional arguments, tuple unpacking and
the signature of zip(),
It moreso relies on the fact that:
t1 = (0,1,2,3)
t2 = (7,6,5,4)
[t1, t2] ==
James Fassett wrote:
zip ...
robust and efficient than the list comprehension.
I don't know the internals of how the Python interpreter treats list
comprehensions and zip but it seems reasonable to assume an extra list
is created for the zip approach.
Minor times differences between this
Hi all,
Had a simple problem that turned into an interesting solution and I
thought I would share it here.
I had a list of tuples that I needed to get the first value from and
generate a list.
tuple_list = (
('John', 'Doe'),
('Mark', 'Mason'),
('Jeff', 'Stevens'),
('Bat', 'Man')
James Fassett:
# the first Pythonic attempt using comprehensions
result_list = [x[0] for x in tuple_list]
# the final functional way
[result_list, _] = zip(*tuple_list)
I really like how Python allows me to do what I feel is the most
natural solution (for a seasoned procedural programmer)
On Jul 11, 3:36 am, [EMAIL PROTECTED] wrote:
James Fassett:
# the first Pythonic attempt using comprehensions
result_list = [x[0] for x in tuple_list]
# the final functional way
[result_list, _] = zip(*tuple_list)
I really like how Python allows me to do what I feel is the most
On Jul 11, 12:00 pm, James Fassett [EMAIL PROTECTED] wrote:
tuple_list = (
('John', 'Doe'),
('Mark', 'Mason'),
('Jeff', 'Stevens'),
('Bat', 'Man')
)
# what I'd do in C or other procedural languages
result_list = []
for item in tuple_list:
[EMAIL PROTECTED] wrote:
James Fassett:
# the first Pythonic attempt using comprehensions
result_list = [x[0] for x in tuple_list]
This has the virtue of working for tuples of any length and doing the
minimal work required.
# the final functional way
[result_list, _] = zip(*tuple_list)
On Jul 11, 1:00 pm, James Fassett [EMAIL PROTECTED] wrote:
Hi all,
Had a simple problem that turned into an interesting solution and I
thought I would share it here.
I had a list of tuples that I needed to get the first value from and
generate a list.
tuple_list = (
('John', 'Doe'),
12 matches
Mail list logo