input_string = "if you can dream it, you can do it"
# The number of characters wanted
chunksize=4
# Without importing re
# Remove spaces
input_string_without_spaces = "".join(input_string.split())
# Result as a list
result_as_list = [input_string_without_spaces[i:i+chunksize] for i in range(0, len(input_string_without_spaces), chunksize)]
# Result as string
result_as_string = " ".join(result_as_list)
print(result_as_string)
一个选项是从输入中去除所有空白,然后在模式
.{1,4}
上使用re.findall
查找所有包含4个字符(或任意多个可用字符)的块。然后按空格将该列表连接在一起以生成最终输出这张照片是:
以下是一个无需导入re的解决方案:
输出:
输出=地狱还是地狱
相关问题 更多 >
编程相关推荐