'How do I combine all the lines in my program into one line on Python?
I want to try and fit my entire program into one line, but I am not sure how to add the for loops and the code that goes underneath the for loops. I have tried ; and : but it is throwing an error in my for loops. Here is my normal code. This is basically a program that generates all possible permutations of a certain length and hashes them and then checks that hash in a txt file to see if it exists.
For everyone who is saying why did you want to do this, I want to earn points for an assignment, since one of the things we have to do is try and fit the entire code into one line. If I was writing code normally, I would not try this, but this was one of our options.
import hashlib
import itertools
pList = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
lineList = []
for i in open ("text.txt"):
lineList.append(i.strip())
for j in range(6):
l = j
set = list(map("".join, itertools.permutations(pList,l)))
for k in range(len(set)):
first = hashlib.md5(set[j].encode())
second = encode.hexdigest()
if second in lineList:
print(set[j])
I have tried to do this, but it is throwing an error, please advise:
import hashlib, itertools; pList = ["A", "B", "C", "D", "E", "F", "G", "H", "I"];lineList = [] ; for i in open ("text.txt"): lineList.append(i.strip())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
