如何在Python中打印嵌套列表的所有可能性?
这是我的列表:
pos = [['det'], ['noun', 'adj'], ['noun'], ['vb'], ['det'], ['vb', 'noun', 'adj']]
或者
pos = ['det', ['noun', 'adj'], 'noun', 'vb', 'det', ['vb', 'noun', 'adj']]
我正在尝试打印所有组合:
det noun noun vb det vb
det adj noun vb det vb
det noun noun vb det noun
det adj noun vb det noun
det noun noun vb det adj
det adj noun vb det adj
我应该使用递归函数吗?我尝试过没有结果。
Itertools(排列、乘积、组合)对我没有帮助。
你能帮我吗?
Here is my list:
pos = [['det'], ['noun', 'adj'], ['noun'], ['vb'], ['det'], ['vb', 'noun', 'adj']]
Or
pos = ['det', ['noun', 'adj'], 'noun', 'vb', 'det', ['vb', 'noun', 'adj']]
I'm trying to print all the combinations:
det noun noun vb det vb
det adj noun vb det vb
det noun noun vb det noun
det adj noun vb det noun
det noun noun vb det adj
det adj noun vb det adj
Should I use recursive function? I tried with no result.
Itertools (permutations, product, combinations) doesn't help me.
Could you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为
itertools.product()
实际上是您正在寻找的内容:打印
I think
itertools.product()
actually is what you are looking for:prints
“itertools”确实有帮助:
'itertools' does help: