Re: [Tutor] For - if - else loop; print selective output

2012-10-26 Thread Alexandre BM
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'], ['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 I print positive matches (*jimmy*) only and not (*Not found*). 
I also want *Not found *to print only /once /if there are no positive 
matches.


On Wednesday, October 24, 2012, 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
not found

I want it to print "yes" for each positive match but nothing for a
negative match. However if all matches are negative, I want it to
print "Not found" once (That bit the code already does). I do I
get it to print "yes" only in a mix result situation?

Saad



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Responding Tweet: A Twitter Bot

2014-02-23 Thread Alexandre BM
Here is a twitter bot that I created, it evaluates math expression then
it reply to the sender
You can study how it works it's pretty simple :)  [1]

[1] https://github.com/rednaks/Twitter-Math-Bot

On 20/02/2014 09:23, Zaki Akhmad wrote:
> Hello,
>
> I am trying to create a twitter bot which respond mentions as soon as
> possible. Here's the detail.
>
> If @someone mention my account @example then in t seconds I would
> respond @someone tweet. I am hoping to get this t less than 60
> seconds.
>
> I would utilize the Mike Verdone twitter API python[1]. My question is
> how to get the mentions as soon as possible, as @someone mention
> @example? Any python library could help me? Hint please.
>
> Previously, I use cron to search for tweets that mentioned @example account.
>
> [1]https://pypi.python.org/pypi/twitter
>
> Thank you,
>

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor