understand how s and s11 shorten one character and then grow one character at a time because there is no loop.

Posted on 2014-08-03
Last Modified: 2014-08-05
def toChars(s):
    import string
    #s = string.lower(s)
    s = s.lower()
    ans = ''
    for c in s:
        #if c in string.lowercase:
        if c in s:
            ans = ans + c
    return ans

def isPal(s):
    if len(s) <= 1:
        return True
        equation=(s[0] == s[-1])
        returnboth=returnequation and returnispal
        return returnboth

def isPalindrome(s):
    """Returns True if s is a palindrome and False otherwise"""
    return returnispal

print (isPalindrome('Guttag'))
print (isPalindrome('Guttug'))
print (isPalindrome('Able was I ere I saw Elba'))
print (isPalindrome('Are we not drawn onward, we few, drawn onward to new era?'))

Open in new window

I created variables so I can see changes in a debugger ide

in def is Palindrome(s)
I do not understand how s and s11 shorten one character and then grow one character at a time because there is no loop.
Question by:rgb192
    LVL 44

    Expert Comment

    the ispal function is being called recursively.

    Author Comment

    or both

    and how
    LVL 44

    Accepted Solution

    isPalindrome is the initial invocation of the isPal function.  The recursion only happens once you are inside the isPal function.  So, I think the answer to your question is 19.

    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
    Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now