Besides the pure python options pointed above, if your list is filled by symbolic expressions, you can also turn it into a vector and do the substitutions straightforwardly.
Given x = list(var('x', n=10)) ep = list(var('epsilon', n=10)) a random sublist my_list = [x[randint(0,8)] for _ in range(6)] and a substitution rule subs_rule = dict(zip(x[4:], ep)) You can make my_vec_list = vector(my_list).subs(subs_rule) and turn back to a list my_list2 = list(my_vec_list) Em terça-feira, 28 de dezembro de 2021 às 15:03:51 UTC-3, Nils Bruin escreveu: > That's a python question. See for instance, > > > https://stackoverflow.com/questions/2582138/finding-and-replacing-elements-in-a-list > > If you scroll down, there are some suggestions there that deal with > multiple replacements as well > > On Tuesday, 28 December 2021 at 06:09:35 UTC-8 cyrille piatecki wrote: > >> First I have seen that perhaps my question has an answer in AskSagemath >> but currently it doesn't answer. >> >> Suppose I have a list of variables x_1, x_2, x_3,...x_n >> >> I have some sub-list of variables say [x_4, x_1, x_6...]. But whenever >> x_4, x_5,x_6 belong to this list I want the substitution x_4 ->epsilon_0, >> x_5 -> epsilon_1... (this is an only an example. Is there a way to do this >> in the same way that we have a substitution in a fonction in Sagemath? >> > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/ded1b03d-32b5-4514-a019-2d8d6dcc9e7bn%40googlegroups.com.