@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:

  1. Row 1 S m l e t
  2. 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)

  • 还是太菜了
  • 熟悉列表切片用法

最新文章

  1. 励志经典,持续收集ing....
  2. smartComplete——轻量级的autoComplete插件,开源
  3. linux安装和配置 mysql、redis 过程中遇到的问题记录
  4. scp使用
  5. jQuery Mobile学习日记之HelloWorld
  6. horizon 修改local的logging 配置
  7. GIT在Linux上的安装和使用简介
  8. HD1385Minimum Transport Cost(Floyd + 输出路径)
  9. Linux 小记录
  10. javaScripte 创建对象。。
  11. 安装xp遇到的问题与如何连接共享的打印机
  12. 整合springboot(app后台框架搭建四)
  13. SQL SERVER的单用户模式以及专用管理员连接
  14. 【Unity与23种设计模式】观察者模式(Observer)
  15. python实战学习之matplotlib绘图续
  16. 解决Android Studio编译后安装apk报错:Error while Installing APK
  17. sed 查找文件的某一行内容
  18. [原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
  19. 创新大师Steve Blank: 你真的知道什么是真正的精益创业吗?
  20. Coursera课程《大家的python》(Python for everyone)课件

热门文章

  1. Exception in thread "main" java.util.ConcurrentModificationException解决方案
  2. pycham更换主题
  3. Hadoop环境搭建|第二篇:hadoop环境搭建
  4. Java并发指南6:Java内存模型JMM总结
  5. mysql 常见面试题
  6. centos7中oracle数据库安装和卸载
  7. Python: 根据利润计算奖金
  8. tortoiseGit did not exit cleanly (exit code 128)
  9. idea使用Snyk对项目进行安全漏洞审核、修复
  10. Windows下Tesseract-OCR的安装