Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

For loop question(skipping)

Hi guys

I'm new in Python so i have an question.
My code work but i know that it's very very bad way to do it.I don't know what is best way to skip big number in for loop

My code:

Code
first = ["a", "b", "c", "d", "e", "f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","-","_","0","1","2","3","4","5","6","7","8","9","."]

    keywords = map(''.join, product(first, repeat=x))
    for key in keywords:
        asd += 1
        if (asd > 100000000):

I'm doing this to skip for loop 100000000 times...It's bad,i know..But what is faster way to skip it? I need to skip big number,because i don't know other way..

Thank you
What is it for? What is it for?
I want to generate all possible character.But i want to skip some(because i'm generate it before..)
This is probably what you need:

PHP Code

<?php 
first 
= ["a", "b", "c", "d", "e", "f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","-","_","0","1","2","3","4","5","6","7","8","9","."]

keywords = map(''.join, product(first, repeat=x))
for 
key in keywords:
    
asd += 1
    
if asd <= len(first): 

This basically says that if asd is smaller or equal to the length of first (40), it'll do whatever you put below the if statement line.
[Image: hW3Ktfp.png]
(Mar 31, 2018 10:37 AM)Vitani Wrote:  This is probably what you need:

PHP Code

<?php 
first 
= ["a", "b", "c", "d", "e", "f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","-","_","0","1","2","3","4","5","6","7","8","9","."]

keywords = map(''.join, product(first, repeat=x))
for 
key in keywords:
 
   asd += 1
    if asd 
<= len(first): 

This basically says that if asd is smaller or equal to the length of first (40), it'll do whatever you put below the if statement line.

I suppose so - the issue from OP is not really clear to me as to what he actually wants to do.

If all he has to do is check if the asd (basically an index now) is less than the length of the "first" list, it's unneccesary since the for loop already iterates over the list
Hello!
There are differents possibilities to do Something like you want. you can use for exemple the "string" module

with something like this (as basic).

>>> import string
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~
>>>
Code
my_list = ["first", "second", "third", "fourth"]
for item in my_list:
   print item
Outputs:
first
second
third
fourth

Code
my_list = ["first", "second", "third", "fourth"]
for item in my_list[2:]:
    print item
Outputs:
third
fourth

So apply the same to "keywords" list by saving the last checked keyword number (i) and then using it inside keywords[last_i_number:]. Save/keep track of last "asd" like:
Code
for key in keywords:
        asd += 1
        print("Last asd = " + str(asd))

And then reuse it like:

Code
for key in keywords[last_asd:]:

Or just save it to file and read it instead of changing the code manually each time, but that's the way in general
(Mar 31, 2018 10:37 AM)Vitani Wrote:  This is probably what you need:

PHP Code

<?php 
first 
= ["a", "b", "c", "d", "e", "f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","-","_","0","1","2","3","4","5","6","7","8","9","."]

keywords = map(''.join, product(first, repeat=x))
for 
key in keywords:
 
   asd += 1
    if asd 
<= len(first): 

This basically says that if asd is smaller or equal to the length of first (40), it'll do whatever you put below the if statement line.

wouldn't this store them all in keywords and then loop over them? should it no be something like this?

PHP Code

<?php 
first 
= ["a", "b", "c", "d", "e", "f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","-","_","0","1","2","3","4","5","6","7","8","9","."]
for 
key in map(''.join, product(first, repeat=x)):
 
   asd += 1
    if asd 
<= len(first): 

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by hoobahstankSep 8, 2018 12:00 PM 0 141 Sep 8, 2018 12:00 PM
Last Post: hoobahstank
[Python] by A!DSFeb 12, 2018 07:29 PM 0 103 Feb 12, 2018 07:29 PM
Last Post: A!DS
[Java] by ohxerxeFeb 4, 2018 03:26 PM 3 306 Feb 4, 2018 03:26 PM
Last Post: matt