any( iterab ) and all( iterab )
as shorthand for reduce( operator.or_, iterab ) and
reduce( operator.and_, iterab ).
What do you think? 7 1682
You are too late, any and all are built-in into python 2.5
Hi, excellent. Now how about something more generic, possibly:
[ x.y() for x or _next_ in c ]
where the context of _next_ is limited in complexity, and/or can only
occur in a generator?
2008/1/7, ca********@gmail.com <ca********@gmail.com>:
You are too late, any and all are built-in into python 2.5
Hi, excellent. Now how about something more generic, possibly:
[ x.y() for x or _next_ in c ]
where the context of _next_ is limited in complexity, and/or can only
occur in a generator?
Would you care to explain what that syntax supposedly means ? By
_next_ you mean something like the next method in generators ? _next_
executes if x is false ? so whatever _next_ returns is named as x, so
you can call x.y() ? I really didn't get your new syntax inside that
list comprehension, neither its uses.
-- http://mail.python.org/mailman/listinfo/python-list
--
-- Guilherme H. Polo Goncalves
On Jan 7, 1:29 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
2008/1/7, castiro...@gmail.com <castiro...@gmail.com>:
You are too late, any and all are built-in into python 2.5
Hi, excellent. Now how about something more generic, possibly:
[ x.y() for x or _next_ in c ]
where the context of _next_ is limited in complexity, and/or can only
occur in a generator?
Would you care to explain what that syntax supposedly means ? By
_next_ you mean something like the next method in generators ? _next_
executes if x is false ? so whatever _next_ returns is named as x, so
you can call x.y() ? I really didn't get your new syntax inside that
list comprehension, neither its uses.
The idea is a shorthand for reduce. Here, _next_ meant the next item
in the iterable c.
On Jan 7, 1:45 pm, castiro...@gmail.com wrote:
On Jan 7, 1:29 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
The idea is a shorthand for reduce. Here, _next_ meant the next item
in the iterable c.
'Only' is another known quantifier in logic: 'all and only'. Any
(there exists) and all (for all) are too. 'Only' (and not others)
could be useful, from the theoretical standpoint. But where?
The idea is a shorthand for reduce. Here, _next_ meant the next item
in the iterable c.
You mean like one of these:
def lookahead(iterator):
i = iter(iterator)
x = i.next()
for item in i:
yield x, item
x = item
def lookahead2(iterator, **kwarg):
i = iter(iterator)
if 'initial' in kwarg:
x = kwarg['initial']
else:
x = i.next()
for item in i:
yield x, item
x = item
if 'last' in kwarg:
yield x, kwarg['last']
print 'lookahead()'
for this, next in lookahead([1,2,3,4,5]):
print this, next
print 'lookahead2()'
for this, next in lookahead2([1,2,3,4,5]):
print this, next
print 'lookahead2(initial=42)'
for this, next in lookahead2([1,2,3,4,5], initial=42):
print this, next
print 'lookahead2(last=42)'
for this, next in lookahead2([1,2,3,4,5], last=42):
print this, next
print 'lookahead2(initial=3.14159, last=42)'
for this, next in lookahead2([1,2,3,4,5],
initial=3.14159, last=42):
print this, next
There are some alternate behaviors that can happen at the end
points, so depending on which behavior you want, the lookahead()
is cleanest, but doesn't allow you to handle edge cases. The
lookahead2() is a little more complex, but allows you to specify
a first item for pairing (so "next" touches every item in your
list) or a trailing element (so "this" touches every item).
-tkc
print 'lookahead2(initial=3.14159, last=42)'
for this, next in lookahead2([1,2,3,4,5],
initial=3.14159, last=42):
print this, next
No, actually. But my mistake.
[ a.b() or _previous_ for a in c ]
means
1 or 2 or 3 or 4 or 5
where c= [ 1, 2, 3, 4, 5].
The mistake: this was not a list comprehension; I wanted to reduce to
a single value.
It's equivalent to reduce( operator.or_, [ 1, 2, 3, 4, 5 ] ), but
disnecessitates lambdas for slightly more complex reductions. But the
example is out of stock. Do we have one? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: SeeBelow |
last post by:
I see the value of a class when two or more instances will be created,
but Python programmers regularly use a class when there will only be one
instance.
What is the benefit of this? It has a...
|
by: Dave |
last post by:
Occasionally, I've seen people write CSS code in shorthand for specifying
font styles. I don't exactly remember how it goes, but sometimes I see
things like this:
SPAN {font: arial, helvetica...
|
by: Andy |
last post by:
I'm a beginning student of CSS and the shorthand order for margins, etc.
raised an eyebrow.
The clockwise order is what bothers me:
p.margin {margin: cm cm cm cm}
I think the order should...
|
by: Montrose... |
last post by:
After working in c# for a year, the only conclusion I can come to is
that I wish I knew c.
All I need is Linux, the gnu c compiler and I can do anything.
Web services are just open sockets...
|
by: Thief_ |
last post by:
Is there a shorthand method for:
Status = Status AND 1
I'm thinking that if you can do:
StatusText &= "Test"
and
|
by: yossi.kreinin |
last post by:
Hi!
There is a system where 0x0 is a valid address, but 0xffffffff isn't.
How can null pointers be treated by a compiler (besides the typical
"solution" of still using 0x0 for "null")?
-...
|
by: Paul |
last post by:
Hi all,
I'm trying to find a declarative way to set server control attributes
using the attribute="<%= SomeValue %>" syntax.
This works fine for basic HTML controls, but server controls will...
|
by: Sheldon |
last post by:
Hi,
This program works when tested with gdb ( see results 1) but when used
in a larger program where 12 becomes 1500 there exists a problem when
freeing the memory ( see results 2). Can anyone...
|
by: =?iso-8859-1?B?dPZmZg==?= |
last post by:
Usually I write something like ...
if (x==1) { doSomething() }
.... and that's how I see it in all the JS references I've found so
far.
But I have seen shorthand (?) for the same thing (?),...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |