You can break the loop when you get a positive matches, and add a
variable where you can count the number of positive matches, if it's
equal to zero print 'not found'
On 24/10/2012 17:43, Saad Javed wrote:
Let me modify this example:
a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies']
On 26/10/12 20:38, Mark Lawrence wrote:
On 26/10/2012 17:58, eryksun wrote:
Sorry, Saad; this is now *way* off topic...
Apart from blatant trolling nothing is off topic on any Python mailing
list.
That's simply not true. The mailing lists mostly have clear topic areas.
This one is for learn
On 26/10/2012 17:58, eryksun wrote:
Sorry, Saad; this is now *way* off topic...
Apart from blatant trolling nothing is off topic on any Python mailing
list. That is one of the joys of reading them. Contrast that to the
mailing lists associated with the group of languages that are based on
Sorry, Saad; this is now *way* off topic...
On Thu, Oct 25, 2012 at 5:39 PM, Oscar Benjamin
wrote:
>
>> degrades if there are many collisions). On average, you can check if a
>> set/dict contains an item in constant time, i.e. O(1). The amortized
>> worst case is O(n).
>
> Why do you say "*amorti
On 26 October 2012 00:08, Steven D'Aprano wrote:
> On 26/10/12 07:16, eryksun wrote:
>>
>> On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit
>> wrote:
>>>
>>>
>>> Do you happen to know offhand if there is a difference between
>>> `in` vs. `in` vs. `in`?
>>
>>
>> The "in" comparison (__contains__ me
On 26/10/12 07:16, eryksun wrote:
On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit
wrote:
Do you happen to know offhand if there is a difference between
`in` vs. `in` vs. `in`?
The "in" comparison (__contains__ method) is equivalent for list and
tuple. It has to search through the sequence it
eryksun wrote:
> On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit
> wrote:
> >
> > Do you happen to know offhand if there is a difference between
> > `in ` vs. `in ` vs. `in `?
>
> The "in" comparison (__contains__ method) is equivalent for list and
> tuple. It has to search through the sequence it
On 25 October 2012 21:16, eryksun wrote:
> On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit
> wrote:
>>
>> Do you happen to know offhand if there is a difference between
>> `in ` vs. `in ` vs. `in `?
>
> The "in" comparison (__contains__ method) is equivalent for list and
> tuple. It has to search
On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit
wrote:
>
> Do you happen to know offhand if there is a difference between
> `in ` vs. `in ` vs. `in `?
The "in" comparison (__contains__ method) is equivalent for list and
tuple. It has to search through the sequence item by item, which makes
it an O
eryksun wrote:
> On Wed, Oct 24, 2012 at 3:24 PM, Alan Gauld wrote:
> > On 24/10/12 18:49, eryksun wrote:
> >
> >> Using "in ['25', '26']" also checks a compiled tuple constant:
> >>
> >> >>> compile("x in ['25', '26']", '', 'eval').co_consts
> >> ('25', '26', ('25', '26'))
> >>
> >> 3.x
On Wed, Oct 24, 2012 at 09:27:30PM +0500, Saad Javed wrote:
> Hi,
>
> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
> '21', 'cookies']]
> for i in a:
> if (i[1] == '25' or i[1] == '26'):
> print 'yes'
> else:
> print 'Not found'
>
> This prints:
> yes
> no
Alan Gauld schreef op wo 24-10-2012 om 17:49 [+0100]:
> I confess I'm not keen on the else part of a for loop and never use
> it,
> I think it leads to more confusion than anything. It doesn't do what
> most folks seem to expect, it should probably be called 'end' or
> something similar rather t
>>> Using "in ['25', '26']" also checks a compiled tuple constant:
>>>
>...
>>> 3.x adds frozenset support:
>>>
>>> >>> compile("x in {'25', '26'}", '', 'eval').co_consts
>>> ('25', '26', frozenset({'25', '26'}))
>>
>>
>> I confess I don't know what that means!
>
>Sorry, I was showing th
On 25/10/12 03:49, Alan Gauld wrote:
I confess I'm not keen on the else part of a for loop and never
use it, I think it leads to more confusion than anything. It
doesn't do what most folks seem to expect, it should probably be
called 'end' or something similar rather than 'else' IMHO.
I am kee
On Wed, Oct 24, 2012 at 3:24 PM, Alan Gauld wrote:
> On 24/10/12 18:49, eryksun wrote:
>
>> Using "in ['25', '26']" also checks a compiled tuple constant:
>>
>> >>> compile("x in ['25', '26']", '', 'eval').co_consts
>> ('25', '26', ('25', '26'))
>>
>> 3.x adds frozenset support:
>>
>>
On 24/10/12 18:49, eryksun wrote:
Using "in ['25', '26']" also checks a compiled tuple constant:
>>> compile("x in ['25', '26']", '', 'eval').co_consts
('25', '26', ('25', '26'))
3.x adds frozenset support:
>>> compile("x in {'25', '26'}", '', 'eval').co_consts
('25', '26'
On Wed, Oct 24, 2012 at 1:30 PM, Joel Goldstick
wrote:
>
>>> if (i[1] == '25' or i[1] == '26'):
>
> like this
> if i[1] in ('25', '26'):
Using "in ['25', '26']" also checks a compiled tuple constant:
>>> compile("x in ['25', '26']", '', 'eval').co_consts
('25', '26', ('25',
On Wed, Oct 24, 2012 at 12:49 PM, Alan Gauld wrote:
> On 24/10/12 17:27, Saad Javed wrote:
>
>> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
>> '21', 'cookies']]
>
>
>> for i in a:
I would change this (which works but I think is simpler
>> if (i[1] == '25' or i[1]
On Oct 24, 2012, at 12:27 PM, tutor-requ...@python.org wrote:
> Hi,
>
> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
> '21', 'cookies']]
> for i in a:
>if (i[1] == '25' or i[1] == '26'):
>print 'yes'
> else:
>print 'Not found'
Suggestion: use names whi
On 24/10/12 17:59, Saad Javed wrote:
Thanks!
If not matched: < does it mean that "if the value of matched is not
true, print Not found"?
Yes exactly. matched starts off as False and will remain that way until
a match is found at which point we set it to True.
--
Alan G
Author of the Le
Thanks!
If not matched: < does it mean that "if the value of matched is not
true, print Not found"?
print "Not found"
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/t
On 24/10/12 17:27, Saad Javed wrote:
a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
'21', 'cookies']]
for i in a:
if (i[1] == '25' or i[1] == '26'):
print 'yes'
else:
print 'Not found'
I want it to print "yes" for each positive match but nothing
Let me modify this example:
a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
'21', 'cookies']]
for i in a:
*b = i[0]*
if (i[1] == '25' or i[1] == '26'):
print *b*
else:
print 'Not found'
This will output:
*jimmy*
*Not found*
*Not found*
*
*
How do
Hi,
a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
'21', 'cookies']]
for i in a:
if (i[1] == '25' or i[1] == '26'):
print 'yes'
else:
print 'Not found'
This prints:
yes
not found
I want it to print "yes" for each positive match but nothing for a negative
m
24 matches
Mail list logo