append - Dumb and Dummer
Alex Martelli
aleaxit at yahoo.com
Mon Oct 4 16:35:07 EDT 2004
More information about the Python-list mailing list
Mon Oct 4 16:35:07 EDT 2004
- Previous message (by thread): append - Dumb and Dummer
- Next message (by thread): append to items depending on prior item
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): append - Dumb and Dummer
- Next message (by thread): append to items depending on prior item
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list