Re: List question

2008-03-21 Thread Ricky Zhou
On 2008-03-21 05:16:41 PM, [EMAIL PROTECTED] wrote:
> alist = [] 
> blist = [ 'one','two','one and two','one and four','five','one two']
> for f in blist:
>   if 'one' and 'two' in f:
>   alist.append(f)
>
> for i in alist:
> print i
> 
> two
> one and two
> one two
> 
> 
> why is it printing the first "two"?

Look at the this line:

if 'one' and 'two' in f:

You're basically saying:

if ('one') and ('two' in f):

which is why you only get elements that contain 'two'.  

Ricky


pgpLDeQ6Gg7ma.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: How to pass a dictionary to a function?

2008-04-07 Thread Ricky Zhou
On 2008-04-07 08:54:09 PM, BonusOnus wrote:
> How do I pass a dictionary to a function as an argument?
> 
> 
> # Say I have a function foo...
> def foo (arg=[]):
Try:

def foo(arg={}):

Thanks,
Ricky


pgpXEZLwP4mLj.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list