Discuss / Python / 写了一下,还是不太懂yield,iterator,generator。

写了一下,还是不太懂yield,iterator,generator。

Topic source

witnessus

#1 Created at ... [Delete] [Delete and Lock User]
def is_palindrome( x ):
    L = [ ]
    while x > 0:
        L.append( x % 10 )
        x = x // 10

    length = len(L)

    for i in range(length):
        if L[i] == L[length - i - 1]:
            continue
        else:
            return False
    return True
# Using IDLE
>>> list(filter(is_palindrome, range(1000)))

  • 1

Reply