在python中迭代到zzz [英] Iterate a to zzz in python

查看:73
本文介绍了在python中迭代到zzz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要得到一个函数,该函数生成一个从a开始并以zzz结尾的字母的列表。



应如下所示:

  a 
b
c
...
aa
ab
ac
...
zzx
zzy
zzz

我当前拥有的代码是:

 用于产品组合(ascii_lowercase,repeat = 3):
print(''。join(combo))

但是,这只会增加3个字母,并且输出更像是

  a 
ab
abc
abcd
。 ..

所以,回顾一下:
字母增加的功能,以及它过去的时间z,它返回到aa。
谢谢!






UPDATE:

p>

我的输出与以前相同。这是我要插入的内容:

  a = hashlib.md5()
,用于链中的字符(ALC,product(ALC,repeat = 1),product(ALC,repeat = 1)):
a.update(chars.encode('utf-8'))
print(''。 join(chars))
print(a.hexdigest())

我的哈希值结束了像这样:

  f1784031a03a8f5b11ead16ab90cc18e 

但我希望:

  415290769594460e2e485922904f345d 

谢谢!

解决方案

 从string import ascii_lowercase as ALC 
(来自itertools导入链),产品

中链中的字符(ALC,product(ALC,repeat = 2),product(ALC,repeat = 3)):
print(''。join(chars))






响应问题更新



我尝试了所有方法,但无法获得 415290769594460e2e485922904f345d 您所说的是您的期望。.所以我不知道您是如何计算期望的。

  product:1a431d62ddd9e78e1b22f8245ad945d0 
排列:52d2529adf73975a4ca82bc7e25db4c6
组合:52bf3fcd925b2fdc1c52df70b7e33cbb
groups_with_replacement:421d5ff16fc211ae253fcc3e81eeb262

So I need to get a function that generates a list of letters that increase from a, and end in zzz.

Should look like this:

a
b
c
...
aa
ab
ac
...
zzx
zzy
zzz

The code I currently have is this:

for combo in product(ascii_lowercase, repeat=3):
            print(''.join(combo))

However, this does only increase with 3 letters, and the output is more like

a
ab
abc
abcd
...

So, to recap: Function that letters increase, and when it goes past z, it returns to aa. Thanks!


UPDATE:

I am having the same output as before. Here is what I am trying to plug it into:

a = hashlib.md5()
for chars in chain(ALC, product(ALC, repeat=1), product(ALC, repeat=1)):
    a.update(chars.encode('utf-8'))
    print(''.join(chars))
    print(a.hexdigest())

My hash ends up like:

f1784031a03a8f5b11ead16ab90cc18e

but I expect:

415290769594460e2e485922904f345d

Thanks!

解决方案

from string import ascii_lowercase as ALC
from itertools import chain, product

for chars in chain(ALC, product(ALC, repeat=2), product(ALC, repeat=3)):
    print(''.join(chars))


RESPONDING TO THE QUESTION UPDATE

I tried all the methods, but couldn't get 415290769594460e2e485922904f345d what you mentioned you expect.. so I don't know how you calculated your expectation.

product                       : 1a431d62ddd9e78e1b22f8245ad945d0
permutations                  : 52d2529adf73975a4ca82bc7e25db4c6
combinations                  : 52bf3fcd925b2fdc1c52df70b7e33cbb
combinations_with_replacement : 421d5ff16fc211ae253fcc3e81eeb262

这篇关于在python中迭代到zzz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆