> On May 19, 2019, at 20:29 , jianrong <lij...@gmail.com> 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 couldn't figure out the mistake. Thank you 
> very much.

It would help to know what “codes do not work” means.  Do you get an error 
message, or does the function f() not produce the result you want.

It may be that you do not have much experience with the Python programming 
language.  There is extensive documentation available at <https://python.org>.

In case your copy of the code you are writing was exactly what you used, the 
problem may be that you are not following the indentation rules that Python 
uses.  This code, which is the same as yours, except for indentation, works for 
me:

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

HTH

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
   Deal with it.
--------



-- 
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@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/47CF431B-A92F-4FC5-8A3A-17B83E4B365D%40mac.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to