Make a sequence of letter combinations start with a specific letter

Asked

Viewed 115 times

0

from string import ascii_uppercase 
import itertools 
import time

for seq in itertools.product(ascii_uppercase,repeat=3):
    sseq = ''.join(seq)
    for z in range(11111, 100000):
            passcode = ('%s%05d' % (sseq, z))
            print(passcode)
            time.sleep(0.5)

The initial exit is:

AAA11111
AAA11112
...

How can I change that and make him start from:

FFF11111
FFF11112
  • Use comments for non-technical information.

  • If one of the answers below solved your problem and there was no doubt left, choose the one you liked the most and mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any doubt or would like further clarification, feel free to comment. If there are still doubts see How and why to accept an answer?

2 answers

3

To start from the "F", just... put the "F" at the beginning. But then it was not clear what you want...


You want it to start from "F" and then go to "Z", excluding all combinations that have the letters from "A" to "E"?

In that case, just use itertools.product(ascii_uppercase[5:], repeat=3) <-- the Slice [5:] take only from "F" onwards (ignoring the letters of "A" and "E"). With this, combinations such as "FAA" and "FEB" will be excluded.


Or you want it to start from the "F", but also include all letters?

In this case, simply rearrange the letters by placing the "F" at the beginning:

letras = 'F' + ascii_uppercase[:5] + ascii_uppercase[6:]
for seq in itertools.product(letras, repeat=3):
    etc...

The Slice [:5] take the letters from "A" to "E", and [6:] takes everything from the "G" onwards (up to the "Z"). So, letras will be FABCDEGHIJKLMNOPQRSTUVWXYZ: you will have all letters (and therefore all possible combinations), but now the first ones will be "FF11111", "FF11112", etc.

  • Thanks bro solved, I’m with a problem of agr time, I have only 2 days to get hit the force after making the request for access( access is only open a link+a passcode in the q url in the case is those generated...AA9999) but in 2 days the link is expired there have q ask dnv and is in this expire before the script get to ZZZ...o requests é muito lento para cumprir o praso q I need, n need to interact with anything on the site, so open the url and ready... You know how to speed that up?

  • @iKrazy If the answer solved your problem, you can accept it, see here how and why to do it. It is not mandatory, but it is a good practice of the site, to indicate to future visitors that it solved the problem. About speeding up the process, I don’t know, if you take the sleep maybe already help...

2

A solution:

from string import ascii_uppercase as au
from itertools import product
import time

bl = "FFF"  # begin_letters
bn = 11111  # begin number

c = [''.join(i) for i in product(au, repeat=len(bl))]
for s in c[c.index(bl):]: 
    while bn < 100000:
        passcode = ('%s%05d' % (s, bn))
        print(passcode)
        time.sleep(0.5)
        bn += 1
    bn = 0
  • You can not vote and the problem is not your answer, is the question that is not clear. The user did not inform if when arriving in ZZZ99999 should end iteration or continue with AAA00000. Maybe if you close cover these two paths get upvotes, at least mine can.

  • @Augustovasques, they are blocked.

  • 1

    I wrote wrong the right one would be ...Maybe if you cover these two paths you can upvotes, at least mine can.... . I was thinking that the question should be closed until the AP gives more clarification. And when I wrote Não dá para votar did not mean an impossibility in the system, I meant that the question is ambiguous because it has two sets of answers and its answer covers only one set and does not address the other and the AP does not hint which way is correct.

  • @Augustovasques, thanks for the clarifications. I think AP wants to get ZZZ99999 in the end because he has the code that fits him. It’s a brute force program and he wants to stop the program at any time and restart it, but not from the beginning.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.