Missing the functional mind set

Kirby Urner urner at alumni.princeton.edu
Sat Mar 3 14:26:51 EST 2001


Daniel Klein <danielk at aracnet.com> wrote:

>Is there a better approach?
>
>Daniel Klein

You might poke values into a list out of order if 
you create the default placeholders in advance.

Instead of:

  >>> params = {}       # dictionary
  >>> params[2] = uv1   # uservalue for param 2
  >>> params[3] = uv2
  >>> params[0] = uv3
  >>> params[1] = uv4

you could go:

  >>> params = [None]*3 # list
  >>> params[2] = uv1   # uservalue for param 2
  >>> params[3] = uv2
  >>> params[1] = uv3
  >>> params[0] = uv4

You'd end up with an ordered list, same as if you'd
stuffed a dictionary and splurted out a list ordered
by key.

Kirby




More information about the Python-list mailing list