EXTREME NOOB, lists?

Ralf Muschall ralf at lipsia.de
Sat Sep 2 09:42:21 EDT 2000


"Alex Martelli" <aleaxit at yahoo.com> writes:

> if a in (4,6,8,10,12,20,100):
>     dice_numbers(a)
> else:
>     print("try again")

If it has to be fast (so that initial setup doesn't matter):

def retry(a):
  print("try again")

Then fill an array (e.g. foo) of length 101 with dice_numbers at
positions 4,6,8,10,12,20,100 and with retry on all other places.

At usage time, just call foo[a](a).

This avoids the nested ifs (explicit as in the question or implicit as
in the "in"-method), but costs an extra indirection.

Ralf



More information about the Python-list mailing list