0

I'm writing a mini diceware program designed to take inputs from the users with real dice, look up the values, and print out their diceware passphrase.

The code I have at the moment works fine and pulls the number and words from a wordlist by searching for the 5-digit diceware identifier (e.g. 34465 jilt).

But, I'm hoping to make the pass phrase print as one line without the number association. e.g. as

"jilt load re open snap" instead of

34465 jilt

load

etc.

At the moment this is that code I'm using:

p_length = int(raw_input("How many dicewords?"))
roll_list = []
for i in range(p_length):
    seq1 = (raw_input("roll 1:"), raw_input("roll 2:"),
            raw_input("roll 3:"), raw_input("roll 4:"),
            raw_input("roll 5:"))
    str1 = "".join(seq1)
    roll_list.append(str1)
    print roll_list

with open("name_list.txt") as f:
    for line in f:
        for x in roll_list:
            if x in line:
                print line

Any suggestions on how to change the last few lines there to do what I'm hoping?

Thanks for the split() advice. Here is my solution:

passphrases = []
with open("name_list.txt") as f:
    for line in f:
    for x in roll_list:
        if x in line:
            var1 = line.split(" ")
            var2 = var1.pop( )
            passphrases.append(var2.rstrip('\n'))

print " ".join(passphrases)

2 Answers 2

1

You can use any here.Updated for just fixing.

for line in f:
    if any(i for i in roll_list if i in line.strip()):
        print line.strip().split(" ")[-1]

>>>hold romeo
Sign up to request clarification or add additional context in comments.

2 Comments

That doesn't work for me. I still get : ['52235', '33213'] 33213 hold 52235 romeo instead of "hold romeo"
what is your input for roll1 ?
1

You can use split to break up a line and extract just the word w/o the number.

1 Comment

And then pick out the second portion of the string to be used I guess?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.