Re: [Tutor] Change dictionary value depending on a conditional statement.

2008-02-13 Thread Terry Carroll
I don't think I saw anyone point this out yet, but, using "list" as a variable name is a bad idea, because it hides the list method. >>> x = list("abcdefg") >>> x ['a', 'b', 'c', 'd', 'e', 'f', 'g'] This works. You now have a variable named "x" that is a list. >>> list = list("hijklmnop") >>> l

Re: [Tutor] Change dictionary value depending on a conditional statement.

2008-02-12 Thread Norman Khine
Thank you all, very nice. Steve Willoughby wrote: > Kent Johnson wrote: >> Try >>list.append({'id': 'name', 'link': ('YY','XX')[total > 0]}) > > I'd caution against that, though. It's clever and cute, sure, but the > meaning of it is obfuscated enough to be unpythonic because [total > 0] >

Re: [Tutor] Change dictionary value depending on a conditional statement.

2008-02-11 Thread Steve Willoughby
Kent Johnson wrote: > Try >list.append({'id': 'name', 'link': ('YY','XX')[total > 0]}) I'd caution against that, though. It's clever and cute, sure, but the meaning of it is obfuscated enough to be unpythonic because [total > 0] as a subscript doesn't mean anything unless you know you're ta

Re: [Tutor] Change dictionary value depending on a conditional statement.

2008-02-11 Thread Kent Johnson
bob gailer wrote: > The terse version: > > list.append({'id': 'name', 'link': ('XX','YY')[total > 0]}) I think you have it backwards: In [1]: total=0 In [2]: ('XX','YY')[total > 0] Out[2]: 'XX' In [3]: total=1 In [4]: ('XX','YY')[total > 0] Out[4]: 'YY' Try list.append({'id': 'name', 'link':

Re: [Tutor] Change dictionary value depending on a conditional statement.

2008-02-11 Thread bob gailer
Norman Khine wrote: > Hello, > Is there a better way to do this: > > >>> list = [] > >>> total = 0 > >>> if total > 0: > ... x = {'id': 'name', 'link': 'XX'} > ... list.append(x) > ... else: > ... y = {'id': 'name', 'link': 'YY'} > ... list.append(y) > ... > > I would like to cha

[Tutor] Change dictionary value depending on a conditional statement.

2008-02-10 Thread Norman Khine
Hello, Is there a better way to do this: >>> list = [] >>> total = 0 >>> if total > 0: ... x = {'id': 'name', 'link': 'XX'} ... list.append(x) ... else: ... y = {'id': 'name', 'link': 'YY'} ... list.append(y) ... I would like to change the key 'link' value depending on the valu