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

2008-04-07 Thread Gabriel Genellina
En Tue, 08 Apr 2008 01:57:47 -0300, Jason Scheirer <[EMAIL PROTECTED]> escribió: > You want to > return s, t > NOT return (s, t) -- this implicitly only returns ONE item To avoid confusing the poor newbie: No, they're absolutely the same thing, in both cases you're returning a tuple with two

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

2008-04-07 Thread Gabriel Genellina
En Tue, 08 Apr 2008 00:54:09 -0300, BonusOnus <[EMAIL PROTECTED]> escribió: > How do I pass a dictionary to a function as an argument? The indentation is lost, so it's not easy to check your program. > # Say I have a function foo... Original: def foo(arg=[]). An empty list isn't a good defaul

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

2008-04-07 Thread Brian
Plus you probably don't want to set [] as default argument and then try to access it like a dictionary; you'll get an exception if you ever call just foo(), with no argument. On Tue, Apr 8, 2008 at 12:57 AM, Jason Scheirer <[EMAIL PROTECTED]> wrote: > On Apr 7, 8:54 pm, BonusOnus <[EMAIL PROTECTE

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

2008-04-07 Thread Jason Scheirer
On Apr 7, 8:54 pm, BonusOnus <[EMAIL PROTECTED]> wrote: > How do I pass a dictionary to a function as an argument? > > # Say I have a function foo... > def foo (arg=[]): > x = arg['name'] > y = arg['len'] > > s = len (x) > > t = s + y > > return (s, t) > > # The dictionary: > > dict = {} > dict['na

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

2008-04-07 Thread Dan Bishop
On Apr 7, 10:54 pm, BonusOnus <[EMAIL PROTECTED]> wrote: > How do I pass a dictionary to a function as an argument? The same way you pass any other argument. > # Say I have a function foo... > def foo (arg=[]): It's generally a bad idea to use [] as a default argument. > x = arg['name'] > y = a

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

2008-04-07 Thread Matt Nordhoff
BonusOnus wrote: > How do I pass a dictionary to a function as an argument? > > > # Say I have a function foo... > def foo (arg=[]): > x = arg['name'] > y = arg['len'] > > s = len (x) > > t = s + y > > return (s, t) I assume you actually indented the body of the function? > # The dictionary:

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-l

Newbie: How to pass a dictionary to a function?

2008-04-07 Thread BonusOnus
How do I pass a dictionary to a function as an argument? # Say I have a function foo... def foo (arg=[]): x = arg['name'] y = arg['len'] s = len (x) t = s + y return (s, t) # The dictionary: dict = {} dict['name'] = 'Joe Shmoe' dict['len'] = 44 # I try to pass the dictionary as an argument