Pyspark Assignment1
Pyspark Assignment1
nums =set([1,1,2,3,3,3,4,4])
print(len(nums))
A. 4
d ={"john":40, "peter":45}print(list(d.keys()))
A.[‘john’,’peter’]
3. A website requires a user to input username and password to register. Write a program to check
the validity of password given by user. Following are the criteria for checking password:1. At least 1
letter between [a-z]2. At least 1 number between [0-9]1. At least 1 letter between [A-Z]3. At least 1
character from [$#@]4. Minimum length of transaction password: 65. Maximum length of
transaction password: 12Hint: In case of input data being supplied to the question, it should be
assumed to be a console input.4.Write a for loop that prints all elements of a list and their position in
the list.a = [4,7,3,2,5,9] Hint: Use Loop to iterate through list elements.
A. import re
def isValidPassword(password):
#Check Max length of the password
if len(password)>12:
return False
#Check Min length of password
if len(password)<7:
return False
#Check Atlease on lower case letter
if not (re.search(r'[a-z]',password)):
return False
#Check Atlease on Upper case letter
if not (re.search(r'[A-Z]',password)):
return False
#Check for atlease one Number
if not (re.search(r'[0-9]',password)):
return False
#Check atlease one character from #@$
if not (re.search(r'[#@$]',password)):
return False
return True
#Call the method
password = input("Enter a password: ")
if isValidPassword(password):
print("Password is valid.")
else:
print("Password is invalid. Ensure it meets all criteria.")
4.Write a for loop that prints all elements of a list and their position in the list.
a = [4,7,3,2,5,9]
A. a = [4,7,3,2,5,9]