# 创建顺序表
n = int(input())
lst = list(map(int, input().split()))

# 输出顺序表中的元素
for i in lst:
    print(i)

# 查找元素位置
target1 = int(input())
target2 = int(input())

pos1 = lst.index(target1) + 1 if target1 in lst else 0
pos2 = lst.index(target2) + 1 if target2 in lst else 0

print(pos1)
print(pos2)

# 翻转顺序表
lst.reverse()

# 输出翻转后的顺序表中的元素
for i in lst:
    print(i)

示例输入:

5
1 2 3 4 5
3
6

示例输出:

1
2
3
4
5
3
0
5
4
3
2
1
Python 顺序表操作:创建、查找、翻转

原文地址: http://www.cveoy.top/t/topic/bAoO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录