• python案例


    回数是指从左向右读和从右向左读都是一样的数,例如12321909。请利用filter()筛选出回数:

    def is_palindrome(n):
        n = str(n)
        length = len(n)
        i=0
        while i < length // 2:
            if(n[i] != n[-i - 1]):
                return False
            i += 1
        return True

    测试数据

    # output = filter(is_palindrome, range(1, 1000))
    # print('1~1000:', list(output))
    # if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]:
    #     print('测试成功!')
    # else:
    #     print('测试失败!')
  • 相关阅读:
    排序
    最小栈
    移除链表元素
    回文链表
    maven自动建立目录骨架
    maven的结构和构建命令
    递归
    链表的中间结点
    括号匹配
    软件工程个人作业01
  • 原文地址:https://www.cnblogs.com/cap-rq/p/13852841.html
Copyright © 2020-2023  润新知