Python 第二式
2024-10-06 16:45:13
@Codewars Python练习
question
** Simple transposition **
Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it.
Complete the function that recieves a string and encrypt it with this simple transposition.
Ex:
For example if the text to encrypt is: "Simple text", the 2 rows will be:
- Row 1 S m l e t
- Row 2 i p e t x
So the result string will be: "Sml etipetx"
solutions
my solutions
def simple_transposition(text):
l1 = []
l2 = []
for i in range(len(text)) :
if i % 2 == 0:
l1.append(text[i])
elif i % 2 != 0:
l2.append(text[i])
return "".join(l1)+"".join(l2)
other solutions
def simple_transposition(text):
return text[::2] + text[1::2]
def simple_transposition(text):
rowOne = True
one = ""
two = ""
for x in text:
if(rowOne):
one += x
else:
two += x
rowOne = not rowOne
return str(one) + str(two)
- 还是太菜了
- 熟悉列表切片用法
最新文章
- 励志经典,持续收集ing....
- smartComplete——轻量级的autoComplete插件,开源
- linux安装和配置 mysql、redis 过程中遇到的问题记录
- scp使用
- jQuery Mobile学习日记之HelloWorld
- horizon 修改local的logging 配置
- GIT在Linux上的安装和使用简介
- HD1385Minimum Transport Cost(Floyd + 输出路径)
- Linux 小记录
- javaScripte 创建对象。。
- 安装xp遇到的问题与如何连接共享的打印机
- 整合springboot(app后台框架搭建四)
- SQL SERVER的单用户模式以及专用管理员连接
- 【Unity与23种设计模式】观察者模式(Observer)
- python实战学习之matplotlib绘图续
- 解决Android Studio编译后安装apk报错:Error while Installing APK
- sed 查找文件的某一行内容
- [原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
- 创新大师Steve Blank: 你真的知道什么是真正的精益创业吗?
- Coursera课程《大家的python》(Python for everyone)课件
热门文章
- Exception in thread ";main"; java.util.ConcurrentModificationException解决方案
- pycham更换主题
- Hadoop环境搭建|第二篇:hadoop环境搭建
- Java并发指南6:Java内存模型JMM总结
- mysql 常见面试题
- centos7中oracle数据库安装和卸载
- Python: 根据利润计算奖金
- tortoiseGit did not exit cleanly (exit code 128)
- idea使用Snyk对项目进行安全漏洞审核、修复
- Windows下Tesseract-OCR的安装