私はpython出力を持っています。これは、tKinter GUIに入力された単語のすべての順列です。出力から取り出されたコメントが必要です。私は置換を使用していますが、これはすべての置換後に空白で終わります。置換を使わないでカンマを削除するPython
def exactMatch(entries):
words = [entry[1].get() for entry in entries]
perms = [p for p in permutations((words))]
x1 = str(perms)
perms2 = x1.replace("," , '')
perms3 = perms2.replace("'" , '') #Takes out the Quotations
perms4 = perms3.replace("(" , '[')
perms5 = perms4.replace(')' , ']\n')
perms6 = perms5.replace (" ", "")
print(perms6)
"a b c hello"
"a b hello c"
"a c b hello"
"a c hello b"
"a hello b c"
"a hello c b"
"b a c hello"
"b a hello c"
"b c a hello"
"b c hello a"
"b hello a c"
上記のように、すべての置換出力には、空白で置き換えられたカンマがあります。私の目標は、空白を使用せず、すべての出力が出力の最初の行と並ぶようにカンマを取り出します。これをどうやってやりますか?どんな助けもありがとうございます。
あなたの機能をpermutations' 'ていますか?定義を教えてください。なぜ処理する前に、順列を文字列に変換していますか?あなたはリストの要素を一緒に結合する 'join'コマンドを知っていますか? –