Check for duplicate characters : Python

def hasDuplicate(str_var):
    """ Checks for repeated characters
        Author: http://www.victorbyte.net
        returns Boolean value """
    for i in range (0, len(str_var)):
        for j in range( i + 1, len(str_var)):
            if str_var[i].lower() == str_var[j].lower():
                return True;

    return False;
This entry was posted in algorithms, python. Bookmark the permalink.

3 Responses to Check for duplicate characters : Python

  1. Emperor says:

    This comment has been removed by the author.

  2. Emperor says:

    This comment has been removed by the author.

  3. Emperor says:

    Here's a one-liner equivalent:

    return any([1 if s.lower().count(c)>1 else 0 for c in set(s.lower())] )

Leave a Reply

Your email address will not be published. Required fields are marked *