[Tutor] optimize code

Norman Khine norman at khine.net
Tue Dec 30 21:42:00 CET 2008


Hi,
I have an updated version at http://paste.lisp.org/display/72843
Thanks for the advice, the code is much smaller and leaner than the 
first attempt.
Norman

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)
> 
> Kent
> 


More information about the Tutor mailing list