In message o0tot492cfjj2g180p15irievp6crpc...@4ax.com, Gilles Ganault
wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
gmail.com
yahoo.com
===
This is why conditional constructs should not accept any values
Lawrence D'Oliveiro wrote:
In message o0tot492cfjj2g180p15irievp6crpc...@4ax.com, Gilles Ganault
wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
gmail.com
yahoo.com
===
This is why conditional constructs
On Thu, Apr 9, 2009 at 2:59 AM, Peter Otten wrote:
Lawrence D'Oliveiro wrote:
This is why conditional constructs should not accept any values other than
True and False.
So you think
if test.find(item) == True: ...
would have been better?
Clearly, any comparison with a boolean literal
On Apr 9, 4:53 pm, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:
In message o0tot492cfjj2g180p15irievp6crpc...@4ax.com, Gilles Ganault
wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
gmail.com
On 9 Apr, 09:49, Miles semantic...@gmail.com wrote:
On Thu, Apr 9, 2009 at 2:59 AM, Peter Otten wrote:
Lawrence D'Oliveiro wrote:
This is why conditional constructs should not accept any values other than
True and False.
So you think
if test.find(item) == True: ...
would have been
On Thu, 09 Apr 2009 18:53:13 +1200, Lawrence D'Oliveiro wrote:
This is why conditional constructs should not accept any values other
than True and False.
I once tried this:
for i in alist.sort():
and got an error I didn't understand because I failed to read the docs.
Clearly for loops
Lawrence D'Oliveiro wrote:
In message o0tot492cfjj2g180p15irievp6crpc...@4ax.com, Gilles Ganault
wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
gmail.com
yahoo.com
===
This is why conditional constructs should not
In message 7e7a386f-d336-4186-822d-
c6af0a581...@e38g2000vbe.googlegroups.com, John Machin wrote:
On Apr 9, 4:53 pm, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:
This is why conditional constructs should not accept any values other
than True and False.
An alternative
Lawrence D'Oliveiro wrote:
Fine if it only happened once. But it's a commonly-made mistake. At some
point you have to conclude that not all those people are stupid, there
really is something wrong with the design.
I think something wrong with the design is overstating the case a bit,
and is
On Apr 10, 12:35 am, John Posner jjpos...@snet.net wrote:
Lawrence D'Oliveiro wrote:
Fine if it only happened once. But it's a commonly-made mistake. At some
point you have to conclude that not all those people are stupid, there
really is something wrong with the design.
I think
2009/4/9 Miles semantic...@gmail.com:
Clearly, any comparison with a boolean literal should be illegal. ;)
Hey, we could have strict type checking at compile time of /all/
operations, couldn't we? Anybody care to join me over at the Ada list?
;-)
--
Tim Rowe
--
John Posner jjpos...@snet.net writes:
Q: Has anyone on the python-dev list ever proposed a string-module
function that does the job of the in operator? Maybe this:
if test.contains(item) # would return a Boolean value
That's a string method, not a function in the string module. If you
Hrvoje Niksic wrote:
if test.contains(item) # would return a Boolean value
That's a string method, not a function in the string module.
Oops, of course.
import operator
operator.contains('foo', 'o')
That's pretty good, and IMHO a bit better than John Machin's suggestion
to use the
John Posner wrote:
Given how common string maniuplations are, I guess I'm surprised that
Python hasn't yet made contains() into both a string-module function
*and* a string-object method.
Could you explain why you prefer 'contains(belly, beer)'
or 'belly.contains(beer)' over 'beer in belly'?
Peter Otten wrote:
John Posner wrote:
Given how common string maniuplations are, I guess I'm surprised that
Python hasn't yet made contains() into both a string-module function
*and* a string-object method.
Could you explain why you prefer 'contains(belly, beer)'
or 'belly.contains(beer)'
Peter Otten wrote:
Could you explain why you prefer 'contains(belly, beer)'
or 'belly.contains(beer)' over 'beer in belly'? The last form may be
a bit
harder to find in the documentation, but once a newbie has learned about
it he'll find it easy to remember.
andrew cooke wrote:
i don't
On Apr 10, 2:36 am, John Posner jjpos...@snet.net wrote:
Hrvoje Niksic wrote:
if test.contains(item) # would return a Boolean value
That's a string method, not a function in the string module.
Oops, of course.
import operator
operator.contains('foo', 'o')
That's pretty
In message grk6ch$73v$0...@news.t-online.com, Peter Otten wrote:
Lawrence D'Oliveiro wrote:
In message o0tot492cfjj2g180p15irievp6crpc...@4ax.com, Gilles Ganault
wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
Gilles Ganault wrote:
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
for item in isp:
if test.find(item):
print item
=== output
gmail.com
yahoo.com
===
Any idea why I'm also getting yahoo.com?
find() returns the index where it is found or -1 if it is not found. Both an
On Wed, 2009-04-08 at 12:01 +0200, Peter Otten wrote:
Gilles Ganault wrote:
I'd like to go through a list of e-mail addresses, and extract those
that belong to well-known ISP's. For some reason I can't figure out,
Python shows the whole list instead of just e-mails that match:
Gilles Ganault nos...@nospam.com writes:
I'd like to go through a list of e-mail addresses, and extract those
that belong to well-known ISP's. For some reason I can't figure out,
Python shows the whole list instead of just e-mails that match:
=== script
test = t...@gmail.com
isp =
Gilles Ganault wrote:
Hello
I'd like to go through a list of e-mail addresses, and extract those
that belong to well-known ISP's. For some reason I can't figure out,
Python shows the whole list instead of just e-mails that match:
=== script
test = t...@gmail.com
isp = [gmail.com,
Remeber the return value of find function of a string is -1 when it
fails, which is True.
Try:
for item in isp:
if item in test:
print item
From: Gilles Ganault nos...@nospam.com
Date: April 8, 2009 5:56:34 PM CST
To: python-list@python.org
Subject: Why does Python show
Gilles Ganault wrote:
I'd like to go through a list of e-mail addresses, and extract those
that belong to well-known ISP's. For some reason I can't figure out,
Python shows the whole list instead of just e-mails that match:
=== script
test = t...@gmail.com
isp = [gmail.com, yahoo.com]
On Wed, 08 Apr 2009 12:11:55 +0200, Ulrich Eckhardt
eckha...@satorlaser.com wrote:
find() returns the index where it is found or -1 if it is not found. Both an
index0 or a -1 evaluate to True when used as conditional expression.
Thanks everyone. I shouldn't have assumed that if test.find(item):
Gilles Ganault wrote:
On Wed, 08 Apr 2009 12:11:55 +0200, Ulrich Eckhardt
eckha...@satorlaser.com wrote:
find() returns the index where it is found or -1 if it is not found. Both
an
index0 or a -1 evaluate to True when used as conditional expression.
Thanks everyone. I shouldn't have assumed
26 matches
Mail list logo