Sep-26-2019, 09:23 AM
If its about string replacement then there can be different scenarios:
(1) Replace one item in list (use assignment as suggested by buran):
(1) Replace one item in list (use assignment as suggested by buran):
>>> foods = ['ham', 'spam'] >>> foods[0] = ' '.join([foods[0], 'and eggs']) >>> foods ['ham and eggs', 'spam'](2) Replace all values, same text:
>>> foods = ['ham', 'spam'] >>> foods = [' '.join([food, 'and eggs']) for food in foods] >>> foods ['ham and eggs', 'spam and eggs'](3) Replace all values, different text:
>>> foods = ['ham', 'spam'] >>> add_ons = ['and eggs', 'and spam'] >>> foods = [' '.join(pair) for pair in zip(foods, add_ons)] >>> foods ['ham and eggs', 'spam and spam']
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.