Python 第二式
@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:
So the result string will be: solutionsmy solutionsdef 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 solutionsdef 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)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |