python-3.x - Creating lists with groups of characters with python
问题描述
People, one question, how can I create this type of list:
['keeab', 'dhabe', 'afebd', 'cabab', 'fkabi', 'kifca', 'bfiai', 'hhjbk', 'jkjij', 'echgf']
Using a character list similar to this:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
I was using this code but it only generates a group of characters
lista = [x for x in "abcdefghijk"]
for i in range(5):
n = random.choice(lista)
#salida: agjef
解决方案
code:
import random
lista = "abcdefghijk"
result = []
for i in range(11):
temp = ""
for j in range(5):
temp += random.choice(lista)
result.append(temp)
print(result)
result:
['fkbjk', 'dcdjf', 'hfbif', 'cbfjb', 'ihikh', 'jjdgi', 'cfjkg', 'idigj', 'kfbaj', 'jgeaa', 'gkjdk']
推荐阅读
- r - 从 NetCDF 中提取矩阵并将其转换为栅格 - 行问题 - R
- http - Flutter Web Http 请求奇怪的响应
- node.js - 如何使用节点 js 发送电子邮件
- php - 提交 Laravel 后如何在文件中创建和保存数据
- c# - 来自 IPublishedContent 的 Umbraco 8 渲染图像
- servicestack - 如何获取 ServiceStack DLL(不是来自 Nuget)?
- flutter - 使用 .pem 文件颤振 grpc 凭据
- azure-devops - Azure DevOps:看不到积压中的所有项目
- ag-grid - React ag grid - 当调用 API 获取更多数据时,bodyScroll 事件在最后一行显示加载器
- azure - 通过 RPD 的 Azure VM 仅显示黑屏和 cmd