This code is in python 3:
I have imported some passwords from a .csv file. The code below takes the passwords from the csv file and turns them into a list. It is passed on from another function then turned into a dictionary.
def buildList(openFile): newList = [] for line in openFile: newList.append(line.strip()) return newList def buildDictionary(newList): newDictionary = {} for password in newList: l = len(password) if l in newDictionary.keys(): newDictionary[l] += 1 else: newDictionary[l] = 1 return newDictionary fileName = input("Enter input file name: ") openFile = open(fileName, "r") newList = buildList(openFile) newDictionary = buildDictionary(newList) print( "\n\nPassword Length Dictionary Entries") print( "%9s%20s" % ( "Length", "Count" ) ) for key in newDictionary.keys(): print("%6d %20d" %(key, newDictionary[key]))
Here is the .csv file
March2021 iudj8&neB09 MyDogWo0f mv3m959 ven1vid1v1c1Iulius 123456789 abcdefgcijk What#ItN0w windsofchange HelloMyNameIs 4584208 4586300 Anniv&0629 BDay@1955 BigBadW0d! !Rf0donotcare R85r!4L145 S3att!eWa SONameHere Abc!23
The output is supposed to recognize the length of each password and match it up with the count. Here is what the code above outputs.
Password Length Dictionary Entries Length Count 39 1 51 1 43 1 45 1 38 1
This is the correct output.
Password Length Dictionary Entries Length Count 9 5 11 2 7 3 18 1 10 5 13 3 6 1
https://stackoverflow.com/questions/66962201/problem-with-string-length-from-a-dictionary April 06, 2021 at 11:06AM
没有评论:
发表评论