Python中怎样对数组中的值进行选择性,调换位置的输出。例如:a,b,c,d,e,f.输出成为a,c,f,e.

如题所述

#调换位置的输出
stin = ['A','B','C','D','E','F','G','H','I','X']

inp = input('enter the sort:')

def change(pa):
    file = open("D:\\dir\\a.txt","a")
    pas = pa.split(',');
    print(pas)
    for i in pas:
        print(stin[int(i)],end=" ")
        file.write(stin[int(i)]+" ")
    file.close()
   
change(inp)

 在D盘创建D:\\dir\\a.txt 查看输出

刚刚玩这个东西,期待高手指点

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-23
Well, without enough details about your problem, no one is able to provide the answer.
But I guess, you are just confused about how to manipulate the python list.
a = [1,2,3]
so you get a list of : a[0] = 1, a[1]=2, a[2]= 3..
Well, same as a array... ( ;) all I can do currently.)
第2个回答  2013-10-22
选择性,调换位置
具体规则是什么啊追问

就是比如说:一组数据:啊,a,b,c,d,e,f,我想让它不输出c,并且输出的时候首先输出f,在输出e.就这种形式。然后写进一个txt文档中。

相似回答