Possible Words using given characters

def charCount(word):

dict = {}

for i in word:

dict[i] = dict.get(i, 0) + 1

return dict

def possible_words(lwords, charSet):

for word in lwords:

flag = 1

chars = charCount(word)

for key in chars:

if key not in charSet:

flag = 0

else:

if charSet.count(key) != chars[key]:

flag = 0

if flag == 1:

print(word)

if __name__ == "__main__":

input = ['goo', 'bat', 'me', 'eat', 'goal', 'boy', 'run']

charSet = ['e', 'o', 'b', 'a', 'm', 'g', 'l']

possible_words(input, charSet)


program to check the validity of a Password

import re

password = "D@m@_u0rtu9e$"

flag = 0

while True:

if (len(password)<8):

flag = -1

break

elif not re.search("[a-z]", password):

flag = -1

break

elif not re.search("[A-Z]", password):

flag = -1

break

elif not re.search("[0-9]", password):

flag = -1

break

elif not re.search("[_@$]", password):

flag = -1

break

elif re.search("\s", password):

flag = -1

break

else:

flag = 0

print("Valid Password")

break

if flag ==-1:

print("Not a Valid Password")