python - Python:通过使用每个其他字母“aceg”来更改像“abcdefg”这样的单词,然后按顺序添加其余的“bdf”。
问题描述
我有这个任务:
您想制作一个代码来隐藏您的消息,但不要让接收者难以解码。每个代码都是小写字母(它将忽略最后一个单词中的最后一个字符以保持标点符号相同)。您将通过使用每隔一个字母“aceg”来更改像“abcdefg”这样的单词,然后按顺序添加其余字母“bdf”。所以“abcdefg”变成了“acegbdf”。请注意,1 或 2 个字母的单词将保持不变。您还必须将每个句子的第一个字母大写。
输入:一个句子将包含所有小写字符。
样本输入:
sentence = ["this", "is", "a", "test", "of", "the", "emergency", "broadcast", "system"]
输出:
"Tihs is a tset of teh eegnymrec bodatracs sseytm."
这就是我到目前为止所拥有的。即使我研究了 Python 书,我也不知道如何处理它,抱歉这里的输入很少!
for word in sentence:
print word[::3],
print word[::1]
解决方案
new_sentence = ''
for word in sentence:
new_sentence += word[::2] + word[1::2] + ' '
print(new_sentence.strip().capitalize())
输出:
Tihs is a tset of teh eegnymrec bodatracs sseytm
推荐阅读
- php - PHP CLI - 错误:在分配给网络的默认值中找不到可用的、不重叠的 IPv4 地址池
- c# - C# 使用 lambda 表达式将参数传递给方法
- javascript - ESDoc:忽略特定文件
- angular - 使用 Rangy 时出错 - 方法在 Angular5 中不起作用
- tensorflow - Keras 自动编码器并获得压缩的特征向量表示
- maven - 链 Maven 存储库以在远程服务器之前选择本地文件系统
- jquery - 如何在 Jquery 中执行文档就绪方法
- python - python notebook类——使用类时如何在标签页上放置数据
- android - BLE Xamarin Android
- jquery - Jquery数据表计算错误的宽度