运维笔试编程题

一、用Python语言把列表[1,3,5,7,9]倒序并将元素变为字符类型,请写出多种方法:

第一种方法:

list = [1, 3, 5, 7, 9]
list.reverse()
list2 = [str(i) for i in list]
print(list2)

第二种方法:

list = [1, 3, 5, 7, 9]
list2 = list[::-1]
list3 = [str(i) for i in list2]
print(list3)

二、Python实现,给定一个字符串,找到字符串中第一个重复的字符。如输入“Hello Duoyi”,输出“l”

a = input("请输入一个字符串:")
b = len(a)
for i in range(0, b):
    c = a.count(a[i])  # 统计某个元素在列表中出现的次数
    if c == 2:
        print(a[i])
        break

 

猜你喜欢

转载自www.cnblogs.com/opsprobe/p/11588507.html
今日推荐