迭代Python中的数组/列表以获取Alpha数字(Iterate Array/List in Python for Alpha Numeric)

编程入门 行业动态 更新时间:2024-10-26 06:27:26
迭代Python中的数组/列表以获取Alpha数字(Iterate Array/List in Python for Alpha Numeric)

什么是在3个独立的场合迭代(AZ + 0-9)的最佳方法。 例如AAA,AAB..AA0,AA1..ZZ0,ZZ1 ......一直到999.数字或字符是否出现在任一插槽中没有限制。

chars = [string.ascii_uppercase + string.digits] genned_chars = [] for char in list(itertools.product(''.join(char), repeat=3)): genned_chars.append(''.join(char))

我从哪里去?

编辑:

while True: chars = string.ascii_uppercase + string.digits genned_chars = [''.join(i) for i in itertools .product(chars,repeat=3)] genned_chars = [''] session = requests.session() session.headers = { 'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53' } page = session.get('URL' + str(genned_chars)) if page.status_code == '302': continue else: with open("validurls.txt","a") as f: f.write( 'URL' + str(genned_chars) + '\n')

What's the best method to iterate through (A-Z + 0-9) on 3 separate occasions that are all exclusive. For instance AAA, AAB..AA0, AA1..ZZ0, ZZ1...all the way to 999. There is no restriction in whether a number or character appears in either slot.

chars = [string.ascii_uppercase + string.digits] genned_chars = [] for char in list(itertools.product(''.join(char), repeat=3)): genned_chars.append(''.join(char))

Where do I go from there?

EDIT:

while True: chars = string.ascii_uppercase + string.digits genned_chars = [''.join(i) for i in itertools .product(chars,repeat=3)] genned_chars = [''] session = requests.session() session.headers = { 'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53' } page = session.get('URL' + str(genned_chars)) if page.status_code == '302': continue else: with open("validurls.txt","a") as f: f.write( 'URL' + str(genned_chars) + '\n')

最满意答案

你不需要将字符串放在列表中,也不要使用list作为生成器,并使用list comprehension来加入产品:

>>> import string >>> chars = string.ascii_uppercase + string.digits >>> genned_chars=[''.join(i) for i in itertools .product(chars,repeat=3)]

You dont need to put the string in list and dont use list for an generator , and use a list comprehension for join the products :

>>> import string >>> chars = string.ascii_uppercase + string.digits >>> genned_chars=[''.join(i) for i in itertools .product(chars,repeat=3)]

更多推荐

本文发布于:2023-07-28 16:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1306840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   迭代   数字   列表   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!