Say I have two lists:
>>> passwordList = ['lee', 'venter', 'rusty']
>>> wrong_num = [5, 5, 0]
I loop the two lists together to combine the two list's corresponding indexes using:
>>>for p, w in zip(passwordList,wrong_num):
>>> newFile.write("The password " + p + " was wrong by " + str(w) + "characters")
The result looks like this:
>>> The password lee was wrong by 5 characters
>>> The password venter was wrong by 5 characters
>>> The password rusty was wrong by 0 characters
My problem comes when I want to include a index variable to make the result look like:
>>>"The password entry 1: lee, was wrong by 5 characters"
>>>"The password entry 2: lee, was wrong by 5 characters"
>>>"The password entry 3: lee, was wrong by 5 characters
I want to index the first list so I can display 1, 2 and 3 for every item in the list. So for this I include another loop that makes the code look like this:
>>>for ind, item in enumerate(passwordList):
>>> for p, w in zip(passwordList,wrong_num):
>>> newFile.write("The password entry " + str(ind) + ": " + p + "is wrong by " + str(w) + " characters")
The result in the file newFile looks like this:
>>> Incorrect password 1: lee, wrong by 5 characters
>>> Incorrect password 1: lee, wrong by 5 characters
>>> Incorrect password 1: lee, wrong by 0 characters
>>> Incorrect password 2: venter, wrong by 5 characters
>>> Incorrect password 2: venter, wrong by 5 characters
>>> Incorrect password 2: venter, wrong by 0 characters
>>> Incorrect password 3: rusty, wrong by 5 characters
>>> Incorrect password 3: rusty, wrong by 5 characters
>>> Incorrect password 3: rusty, wrong by 0 characters
How can I stop this from happening and rather only print:
>>> Incorrect password 1 : lee, wrong by 5 characters
>>> Incorrect password 2 : venter, wrong by 5 characters
>>> Incorrect password 3: rusty, wrong by 0 characters
This is just for the theory, so please ignore that "rusty is wrong by 0 characters" still says incorrect password at the beginning of the sting.