Python删除逗号而不使用rep

2024-09-30 04:37:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python输出,它是输入到tkintergui的所有单词的排列。我需要从输出中去掉逗号。我使用了replace,但每次排列后都会出现一个空格。你知道吗

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"

正如您在上面所看到的,每个排列输出都有一个逗号,我用一个空格替换了它。我的目标是不使用空格,而是去掉逗号,以便所有输出与输出的第一行对齐。我该怎么做呢?感谢您的帮助。你知道吗


Tags: inhelloforreplaceentrieswords空格entry

热门问题