Ai
2 Star 1 Fork 1

望曦开源团队/Python案例合集

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SwapPositions-3.py 443 Bytes
一键复制 编辑 原始数据 按行查看 历史
NineSenz-九练 提交于 2023-04-27 00:00 +08:00 . 列表翻转指定位置的元素
'''
定义一个列表,并将列表中的指定位置的两个元素对调。
例如,对调第一个和第三个元素:
对调前 : List = [23, 65, 19, 90], pos1 = 1, pos2 = 3
对调后 : [19, 65, 23, 90]
'''
def swapPositions(list, pos1, pos2):
get = list[pos1], list[pos2]
list[pos2], list[pos1] = get
return list
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3
print(swapPositions(List, pos1-1, pos2-1))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wangxios/workspace_Python.git
git@gitee.com:wangxios/workspace_Python.git
wangxios
workspace_Python
Python案例合集
master

搜索帮助