两个字符串,如:
import random
consonants = "bcdfghjklmnprstvwz"
vowels = "aeiou"
我想在偶数索引中得到四个字母,在奇数索引中得到三个字母,比如:
ejiguka / agewilu / isavonu (odd indexes(0,2,4,6),even indexes(1,3,5,7))
我试过这个函数,但不起作用。你知道吗
random_letter = random.choice(consonants[::2])
random_letter1 = random.choice(vowels[1::2])
random_together = random_letter + random_letter1
我得到了两个随机的字母,比如b
和e
,但是我想得到输出,比如ejiguka
/agewilu
。你知道吗
您可以创建一个字母列表,并按如下方式将它们连接在一起:
您的代码只从每个列表中获取一个字母,并且只从切片项中获取一个字母。你知道吗
你在正确的轨道上拼接,但你没有应用它的权利。你知道吗
首先初始化空列表:
现在,在拼接中赋值,使用
random.sample
检索唯一的随机字符子集:加入并打印:
相关问题 更多 >
编程相关推荐