【问题标题】:How to generate all possible combination of words (Python)如何生成所有可能的单词组合(Python)
【发布时间】:2022-08-24 14:51:57
【问题描述】:

假设我们有 6 个字符串:

Input: [\"Love\", \"Is\", \"What\", \"I\", \"Care\", \"About\"]

那么我该怎么做才能找到输出的所有单词组合:

爱是我所关心的

爱是我所关心的

关于关心我什么是爱

以此类推,不重复


我是新手,希望你们能帮助我。

非常感谢

标签: python combinations permutation


【解决方案1】:
>>> import itertools
>>> inputs = ["Love", "Is", "What", "I", "Care", "About"]
>>> list(itertools.permutations(inputs, len(inputs)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多