append to items depending on prior item

M. Clift noone at here.com
Sun Oct 3 13:55:24 EDT 2004


Hi Peter,

Thankyou, it looks perfect. At the risk of sounding dumb, however, what do I
print to get your output?

 items = "item1 item4 item2 item1".split()
[i + random.choice(dict(item1="abc", item2="def").get(p, [""]))
 for (p,i) in zip(items[-1:]+items[:-1], items)]
print ???

Thanks,

M





More information about the Python-list mailing list