'Is there a way to loop through a list and use them individually as an index?
I have two lists, what I'd like to know how to do is use the values in the first list as indexes in the second. Then I can append each iteration to a new list.
out_pass = ['w', 'Q', '4', 'z', 'e', 'h', '8', '9', '!', '@', '3', 'A']
Lines = [2, 4, 5, 8, 11, 6, 0, 10, 1, 3, 7, 9]
fin = 0
fin_pass = []
while fin < Len(lines)
fin_pass.append(out_pass[2]) <-- Then 4, 5, 8 etc...
fin += 1
Solution 1:[1]
Here's a version of your code that I think does what you want, keeping the structure pretty much the same:
out_pass = ['w', 'Q', '4', 'z', 'e', 'h', '8', '9', '!', '@', '3', 'A']
lines = [2, 4, 5, 8, 11, 6, 0, 10, 1, 3, 7, 9]
fin_pass = []
for line in lines:
fin_pass.append(out_pass[line])
print(fin_pass)
Result:
['4', 'e', 'h', '!', 'A', '8', 'w', '3', 'Q', 'z', '9', '@']
Note: I renamed a few things, but mostly please note that I changed Lines to lines. You should capitalize Type names but variable names should always be lowercase. This is just a convention, but it's one that is quite universal, and not following it will make your code more difficult for others to read and understand.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CryptoFool |
