check pass boolean function

129
January 09, 2018, at 6:11 PM

This is my code which and it asks a user to enter a password string and checks for any repeated elements.The thing is I didn't understand the code and why they set a unique_element to an empty string.And what does unique+=password[i] do,why is i in [] in this brackets?

def check_pass():     
    password= raw_input('Enter a password:')
    unique_element = ''
    for i in range (len(password)):
        if len(unique_element) == 0:
            unique_element += password [i]     
        else:
            not_unique = True
            for j in range (len(unique_element)):
                if unique_element[j] == password[i]:
                    not_unique = False
            if not_unique:
                unique_element += password[i]
    return unique_element == password
print check_pass()
Answer 1

Explaining the Code above may be a little tedious. Suffice it to say that if your intention is to check if a given String [password] contains any duplicate character, you might do that without the need for any loops - which (in this case) is likely unnecessary. Here's how:

def pass_has_unique_characters():
    # CAPTURE THE ENTERED CHARACTERS
    password        = input('Enter a password:')
    # SETS CANNOT HAVE DUPLICATES SO WE CAST THE STRING (password) TO A SET
    st_password     = set(password)
    # NOW WE CHECK THE LENGTHS OF BOTH: password AND st_password
    # IF BOTH HAVE THE SAME LENGTH, THEN THE PASS HAS UNIQUE CHARACTERS, 
    # RETURN [True] ... OTHERWISE RETURN [False]
    return (True if len(st_password) == len(password) else False)

print(pass_has_unique_characters())
READ ALSO
Pyuic4 not found on centos7

Pyuic4 not found on centos7

I have installed PyQt4 onto cent OS 7 then i can able to import package PyQt4, but when i try to run on the terminal **pyuic4 -w user_interface_file > python file it says

246
Raspberry Pi google assiatant not working

Raspberry Pi google assiatant not working

Please help! I am making a google assistant on my raspeberry piBut at the end when i type (env) pi@Raspberrypi:~ $ python -m googlesamples

296
abaqus python, why are the extracted displacement values different?

abaqus python, why are the extracted displacement values different?

I am trying to use abaqus-ython scripting to extract the nodal coordinatesin doing so i first extract the original nodal positions and then add the displacement value

176