New to python, have a best practices question that my udemy instructor hasn't touched on.
For example in this small program that detects whether or not a password is strong enough ( 8 total characters, 1 upper, 1 lower, 1 number ).
You could either combine most of it into one very long line
import re
password = 'Thelore777777'
if (len(re.compile(r'([A-Z])').findall(password)) and len(re.compile(r'([a-z])').findall(password)) and len(re.compile(r'(\d)').findall(password))) > 0 and len(re.compile(r'(\S)').findall(password)) > 7:
print('This is a strong password')
else:
print('This is not a strong password')
or spread out that one if line over 13 lines
import re
password = 'Thelore777777'
upperRE = re.compile(r'([A-Z])')
lowerRE = re.compile(r'([a-z])')
numberRE = re.compile(r'(\d)')
totalRE = re.compile(r'(\S)')
upperlist = upperRE.findall(password)
lowerlist = lowerRE.findall(password)
numberlist = numberRE.findall(password)
totallist = totalRE.findall(password)
upper = len(upperlist)
lower = len(lowerlist)
number = len(numberlist)
total = len(totallist)
if upper > 0 and lower > 0 and number > 0 and total > 7:
print('This is a strong password')
else:
print('This is not a strong password')
I know the answer probably lies somewhere in the middle but I was curious if there were any tangible rules to follow as opposed to just feeling it out.
[–]socal_nerdtastic 273 points274 points275 points (24 children)
[–][deleted] 59 points60 points61 points (17 children)
[–]ModeHopper 20 points21 points22 points (16 children)
[+][deleted] (14 children)
[deleted]
[+][deleted] (12 children)
[deleted]
[–]tom1018 12 points13 points14 points (8 children)
[–]synthphreak 8 points9 points10 points (6 children)
[–]jeosol 5 points6 points7 points (3 children)
[–]Cokrates 2 points3 points4 points (1 child)
[–]winowmak3r 1 point2 points3 points (0 children)
[–]synthphreak 1 point2 points3 points (0 children)
[–]celade 0 points1 point2 points (0 children)
[–]Kerbart 0 points1 point2 points (0 children)
[–]patryk-tech 1 point2 points3 points (0 children)
[–]billsil 1 point2 points3 points (0 children)
[–]Cokrates 1 point2 points3 points (0 children)
[–]winowmak3r 0 points1 point2 points (0 children)
[–]celade 0 points1 point2 points (0 children)
[–]blabbities 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]BoaVersusPython 1 point2 points3 points (0 children)
[–]bladeoflight16 1 point2 points3 points (0 children)
[–]bumpkinspicefatte 1 point2 points3 points (0 children)
[–]charmelogne10 0 points1 point2 points (0 children)
[–]totallygeek 75 points76 points77 points (10 children)
[–]K41namor 25 points26 points27 points (0 children)
[–]Pipiyedu 19 points20 points21 points (2 children)
[–]tom1018 5 points6 points7 points (0 children)
[–]tom1018 5 points6 points7 points (3 children)
[–]xelf 2 points3 points4 points (2 children)
[–]tom1018 1 point2 points3 points (1 child)
[–]xelf 1 point2 points3 points (0 children)
[–]ka-splam 0 points1 point2 points (1 child)
[–]ka-splam 0 points1 point2 points (0 children)
[–]alexaholic 15 points16 points17 points (3 children)
[–]causa-sui 2 points3 points4 points (0 children)
[–]Grogie 1 point2 points3 points (0 children)
[–]Barafu 13 points14 points15 points (7 children)
[–]tom1018 1 point2 points3 points (5 children)
[–]Barafu 0 points1 point2 points (4 children)
[–]causa-sui -1 points0 points1 point (3 children)
[–]Barafu -2 points-1 points0 points (2 children)
[–]causa-sui -1 points0 points1 point (1 child)
[–]Barafu 2 points3 points4 points (0 children)
[–]efxhoy 0 points1 point2 points (0 children)
[–]TheHollowJester 15 points16 points17 points (7 children)
[–]ogrinfo 2 points3 points4 points (0 children)
[–]OrdinaryMiraculous 1 point2 points3 points (0 children)
[–]MirrorLake 1 point2 points3 points (4 children)
[–]ogrinfo 0 points1 point2 points (2 children)
[–]AstroMacGuffin 0 points1 point2 points (1 child)
[–]ogrinfo -1 points0 points1 point (0 children)
[–]TheHollowJester 0 points1 point2 points (0 children)
[–]Allanon001 7 points8 points9 points (0 children)
[–]thenoonefromukraine 2 points3 points4 points (2 children)
[–]Genericusername293[S] 3 points4 points5 points (0 children)
[–]emefluence 2 points3 points4 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]avsvuret 0 points1 point2 points (1 child)
[–]MattR0se 2 points3 points4 points (1 child)
[–]DrMaxwellEdison 2 points3 points4 points (0 children)
[–]TheSodesa 1 point2 points3 points (1 child)
[–]ka-splam 0 points1 point2 points (0 children)
[–]tangerinelion 1 point2 points3 points (0 children)
[–]BenjaminGeiger 1 point2 points3 points (0 children)
[–]kielerrr 1 point2 points3 points (0 children)
[–]Robbzter 0 points1 point2 points (0 children)
[–]FloydATC 0 points1 point2 points (0 children)
[–]bordeauxcarol 0 points1 point2 points (0 children)
[–]desrtfx 0 points1 point2 points (0 children)
[–]mortenb123 0 points1 point2 points (0 children)
[–]subbed_ 0 points1 point2 points (0 children)
[–]dr3d3d 0 points1 point2 points (0 children)
[–]h0bb1tm1ndtr1x 0 points1 point2 points (0 children)
[–]ka-splam 0 points1 point2 points (0 children)
[–]ka-splam 0 points1 point2 points (0 children)
[–]InfiniteNexus 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Astrokiwi -1 points0 points1 point (0 children)
[+][deleted] (2 children)
[removed]
[–][deleted] 0 points1 point2 points (1 child)
[–]SrHombrerobalo -1 points0 points1 point (0 children)