Re: [sage-support] How to permute a list of elements in sage

2019-05-20 Thread Daniel Krenn
On 20.05.19 05:29, jianrong wrote: > I am trying to write a function in sage to permute a list of elements. An alternative might me something along the following: | Permutation("(1,2,3)(4,5)").action(['a', 'b', 'c', 'd', 'e']) | -- You received this message because you are subscribed to the Goo

Re: [sage-support] How to permute a list of elements in sage

2019-05-20 Thread slelievre
Simplifying the function and adding a docstring with an example: def f(i, v1): r""" Return a copy of this list with elements of index `i` and `i + 1` swapped. EXAMPLE:: sage: l = [5, 4, 3, 2, 1, 0] sage: f(3, l) [5, 4, 3, 1, 2, 0] """ v = list(v1)

Re: [sage-support] How to permute a list of elements in sage

2019-05-20 Thread jianrong
Thank you very much! -- 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 post to this group, send email to sage-support

Re: [sage-support] How to permute a list of elements in sage

2019-05-19 Thread 'Justin C. Walker' via sage-support
> On May 19, 2019, at 20:29 , jianrong wrote: > > Dear All, > > I am trying to write a function in sage to permute a list of elements. > > def f(i, v1): > v=[] > for j in v1: >v.append(j) > > print(v) > v[i+1]=v1[i] > v[i]=v1[i+1] > return v > > But the above codes do not work. I could

[sage-support] How to permute a list of elements in sage

2019-05-19 Thread jianrong
Dear All, I am trying to write a function in sage to permute a list of elements. def f(i, v1): v=[] for j in v1: v.append(j) print(v) v[i+1]=v1[i] v[i]=v1[i+1] return v But the above codes do not work. I couldn't figure out the mistake. Thank you very much. -- You received this message b