创建可能案例的简单方法
我有数据列表,例如
a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
我想创建一个新的另一个列表,该列表是由 a、b、c 的所有可能情况混合而成的 是否
d = ["1a001","1a002","1a003",...,"4e003"]
有任何模块或方法可以生成 d 而无需编写许多 for 循环?
I have lists of data such as
a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
And I want to create new another list that was mixed from all possible case of a,b,c like this
d = ["1a001","1a002","1a003",...,"4e003"]
Is there any module or method to generate d without write many for loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您也将
a
转换为str
列表,那么这样做会更简单。并节省了对 b 和 c 的每个元素不必要的调用
str()
这是时间比较
This is a little simpler to do if you convert
a
to be a list ofstr
too.and saves needlessly calling
str()
on each element of b and cHere is a timing comparison
这个怎么样?使用地图
How about this? Using
map