gpt4 book ai didi

用于生成字符串中可能的字符串替换的所有排列的 Python 模块?

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:02 25 4
gpt4 key购买 nike

<分区>

template = "{{ person }} is a {{ quality }} {{ occupation }}"
replacements = {
"person":["John","Matt","Steve"],
"quality":["great","dedicated"],
"occupation":["engineer","student","athelete"]
}

Output:
John is a great engineer
Matt is a great engineer
Steve is a great engineer
John is a dedicated engineer
Matt is a dedicated engineer
Steve is a dedicated engineer
John is a great student
Matt is a great student
Steve is a great student
.............................

它们可以通过使用可替换元素列表的列表并循环它们以生成排列,然后加入列表元素来生成。

list_input =     [["John","Matt","Steve"],["is"],["a"],["great","dedicated"],["engineer","student","athelete"]]

example_permutation = ["John","is","a","great","engineer"]

是否有可以生成类似排列的 python 模块/方法?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com