Python - 如何从列表中删除逗号,方括号和引号

时间:2016-01-22 12:08:53

标签: python listview

如何从此结果中删除引号,逗号和括号:

    encrypt = input("enter your string: ")
    encrypt = encrypt.replace(" ","")
    encrypt_list = [encrypt[i:i+5] for i in range(0, len(encrypt), 5)]
    print (encrypt)
    print (encrypt_list)

如果输入为:5 blocks of text test

输出为:['5bloc', 'ksoft', 'extte', 'st']

我需要它:5bloc ksoft extte st

1 个答案:

答案 0 :(得分:0)

您可以使用str.join,如下所示:

>>> s = ' '.join(['5bloc', 'ksoft', 'extte', 'st'])
>>> print(s)
5bloc ksoft extte st