Search code examples
pythonlistelementcontain

Checking elements in the list


I've spend few hours solving this problem but program doesn't work (syntax error). Cheking an answer for similar question didn't help. What's wrong with the code below? I want to chek if list (password) contains at least one digit, as well as containing one uppercase letter and one lowercase letter in it. Please, provide me with the simplest way, I'm a beginner ...

def checkio(password):    
    array = list(password)
    #for letter in array:
    if len(array) < 10 or len(array) > 64:
        return False
    if (any(l.isdigit() for l in array) and (any(l.isupper( for l in array) and (any(l.islower for l in array):
        return True
    else:
        return False

Solution

  • Your parentheses are very wrong. try this.

    def checkio(password):    
      array = list(password)
      #for letter in array:
      if len(array) < 10 or len(array) > 64:
          return False
      if ((any(l.isdigit() for l in array)) and (any(l.isupper() for l in array)) and ((any(l.islower() for l in array)))):
          return True
      else:
          return False