[Tutor] optimize code
Norman Khine
norman at khine.net
Tue Dec 30 16:56:32 CET 2008
Kent Johnson wrote:
> On Tue, Dec 30, 2008 at 9:32 AM, Norman Khine <norman at khine.net> wrote:
>> Hello,
>> I have this piece of code which I would like to further streamline it.
>
> There is no need to re-create the mapping at each level of if; you can
> just add new key/value pairs. For example
> if level2 is not None:
> mapping['level2'] = level2
>
>> What the code does is that it takes a form value and builds a dictionary
>
> It seems that the you are really returning a string, or at least
> building a string to pass to gettext(). I would have each if statement
> just append to the string. That would consolidate the return
> statements. For example, if value is the string being built,
> if level2 is not None:
> value = '%s: %s' % (value, level2)
Thanks, it is very helpful.
Norman
More information about the Tutor
mailing list