append to items depending on prior item
M. Clift
noone at here.com
Sun Oct 3 10:23:11 EDT 2004
Hi All,
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
previous item.
from random import *
items = [' item1',' item4',' item2',' item1']
items[0].append choice('1','2','3')
print items
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')
print items
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
Thanks,
M
More information about the Python-list
mailing list