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"]
유사한 순열을 생성 할 수있는 파이썬 모듈/방법이 있습니까? 는 IS
(제안) 목록
또는 당신이 당신의 DICT의 @dano에서 직접 할 수있는이 단지
cartesian product
, 원하는 모듈. :/ – geoffspear@Wooble, itertools에 지원 방법이 있는지 확실하지 않았지만, 순열을 생성하는 itertools 만 알았지 만,이 경우에는 데카르트 제품이라고 생각하지 않았습니다. – DhruvPathak