append to items depending on prior item
noone at here.com
Sun Oct 3 16:23:11 CEST 2004
I have tried to come up with a way to do this myself and all I end up with
is very long code.
What I have is a say item1, item4, item2, item1 etc...
What I want to do is append to each item an extra value depending on the
from random import *
items = [' item1',' item4',' item2',' item1']
for idx in range(len(items)):
if previous item == ['item1']:
next item.append choice('a','b','c')
if previous item == ['item2']:
next item.append choice('d','e','f')
appended items = item1b, item4a, item2f etc...
Now I know that the code is hopelessly wrong - you can't append a string,
but you get the idea. Doing it using if statements could go on and on. Could
someone show me a short way
More information about the Python-list