怎么用python编写一个能随机生成20个3到7位随机字母组合的函数,求大佬

怎么用python编写一个能随机生成20个3到7位随机字母组合的函数,求大佬帮忙!

#!/usr/bin/env python 
# -*- coding: UTF-8 -*- 
#python2.7 

import string,random
def get_clice(num):
    res =[] 
    tmp = list(string.lowercase)
    for i in range(num):
        res.append(''.join(random.sample(tmp,random.randint(3,7))))
    return res
print get_clice(20)

追问

能用python3.6写个吗

追答#!/usr/bin/python
# -*- coding: utf-8 -*-
#python3.x
import string,random
def get_clice(num):
    res =[] 
    tmp=string.ascii_letters #py3 这个函数把大小写都包括进去了
    for i in range(num):
        res.append(''.join(random.sample(tmp,random.randint(3,7))))
    return res
print(get_clice(20))

温馨提示:答案为网友推荐,仅供参考
相似回答