append - Dumb and Dummer

Alex Martelli aleaxit at yahoo.com
Mon Oct 4 16:35:07 EDT 2004


M. Clift <noone at here.com> wrote:

> Hi Alex,
> 
> How do I print from this?
> 
> def weird_appender(sequence):
>     first_time_choices = {'item1': 'abc', 'item2': 'def', }
>     choices = { None: first_time_choices,
>                 'item1': {'item1': 'blu', 'item2': 'ghi', },
>                 'item2': {'item1': 'jkm', 'item2': 'nop', }
>               }
> 
>     d = choices.get(previous, first_time_choices)
>     choose = d.get(item, [''])
>     yield item + random.choice(choose)
>     previous = item
> 
> print ???

Hmmm, that depends on what (if anything) you _wish_ to print, doesn't
it?  print list(weird_appender(whatever_weird_sequence)) is one
possibility, but surely not the only one...


Alex



More information about the Python-list mailing list