2019独角兽企业重金招聘Python工程师标准>>>

http://www.pythonchallenge.com/pc/def/map.html

http://wiki.pythonchallenge.com/index.php?title=Level1:Main_Page

#!/usr/bin/env python
#-*- coding: utf-8 -*-
#Level1_Sol1.py
import string
text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
def Sol1():#First, load the text and create a translation table.#string.ascii_lowercase: The lowercase letters 'abcdefghijklmnopqrstuvwxy'. This value is not locale-dependent and will not change.table = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:]+string.ascii_lowercase[:2])print "table is ", repr(table), "\nlen(table) is ", len(table), "\ntype(table) is ", type(table)print "------------------------"#Now, we apply the translation table on the string.newstr1 = string.translate(text, table)print "newstr1 is ", newstr1print "------------------------"#Alternatively, just use the translate on the "text" variable.newstr2 = text.translate(table)print "text is ", textprint ">>>>>>>>>>>>>>>>>>>>>>>>"print "newstr2 is ", newstr2
def Sol2():'''Solved without translate'''tmp_str = ""for x in text:if ord(x) >= ord('a') and ord(x) <= ord('z'):tmp_str += chr((ord(x) + 2 - ord('a'))%26 + ord('a'))else:tmp_str += xprint "tmp_str is ", tmp_str
def Sol3():'''Similar to Sol2() but with some of 2.5's nested ternary operators'''for x in text:print chr(ord(x) if ord(x)+2 < ord('a') else ord(x) + 2 if ord(x)+2 < ord('z') else ord(x) - 24),
def Sol4():'''With a dictionary'''"""zip([iterable, ...])zip()是python的一个内建函数,它接受一系列可迭代的对象作为参数,可把两个或多个序列中的相应项合并在一起,将对象中对应的元素打包成一个个tuple元组,然后返回由这些tuples组成的list(列表)。若输入参数的长度不等,则返回list的长度和参数中长度最短的对象相同。利用*号操作符,可以将list unzip(解压)>>> a = [1,2,3]>>> b = [4,5,6]>>> c = [7,8,9,0]>>> zipped = zip(a,b)>>> zipped[(1, 4), (2, 5), (3, 6)]>>> zipped = zip(a,b,c)>>> zipped[(1, 4, 7), (2, 5, 8), (3, 6, 9)]>>> zip(a,c)[(1, 7), (2, 8), (3, 9)]>>> zip(*zipped)[(1, 2, 3), (4, 5, 6), (7, 8, 9)]dict() -> new empty dictionarydict(mapping) -> new dictionary initialized from a mapping object's(key, value) pairsdict(iterable) -> new dictionary initialized as if via:d = {}for k, v in iterable:d[k] = vdict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.  For example:  dict(one=1, two=2)"""cypher = dict(zip(string.lowercase, string.lowercase[2:] + string.lowercase[:2]))#dict.get(key, default=None)对字典dict中的键key,返回它对应的值value,如果字典中不存在此键,则返回default的值。注意,参数default的默认值为None.print "cypher is ", cypherprint "".join(cypher.get(c,c) for c in text)if __name__ == '__main__':#Sol1()#Sol2()#Sol3()Sol4()

Do by myself:

str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
lists = str.split()
list1 = []
for str1 in lists:str2 = ''for ch in str1:if ch == '.' or ch == '\'' or ch == '(' or ch == ')':str2 += chelse:str2 += chr(ord(ch)+2)str2 = str2.replace('{','a')str2 = str2.replace('|','b')list1.append(str2)
print(" ".join(list1))

转载于:https://my.oschina.net/u/1178546/blog/165808

Python Challenge-Level 1相关推荐

  1. python challenge 答案

    Level 0 [1] Hint: try to change the URL address. 第零关主要让人熟悉游戏规则和形式.首先观察标签栏主题显示的是warming up,表明这关的主题是热身 ...

  2. the python challenge_The Python Challenge 谜题全解(持续更新)

    Python Challenge(0-2) 是个很有意思的网站,可以磨练使用python的技巧,每一关都有挑战,要编写相应的代码算出关键词,才可以获取下一关的url,还是很好玩的QAQ LEVEL 0 ...

  3. 有趣的Python Challenge编程解谜游戏攻略二(5-9关)

    **有趣的Python Challenge编程解谜游戏攻略二(5-9关)** 介绍 游戏介绍 0-4关攻略 写在前面 关卡 第5关 第6关 第7关 第8关 第9关 链接总结 第10关预告 介绍 游戏介 ...

  4. the python challenge_The Python Challenge 解密之旅

    本文是记录博主运用 Python 来解决 The Python Challenge 站点中每个关卡的难题. 说明:本文为博主自主原创,允许转载,但是必须标明来源出处及其作者,谢谢! The Pytho ...

  5. Python Challenge 第 2 关攻略:ocr

    Python Challenge 第 2 关攻略:ocr 题目地址 http://www.pythonchallenge.com/pc/def/ocr.html 题目内容 recognize the ...

  6. (转)一个古老的编程游戏:Python Challenge全通攻略

    为什么80%的码农都做不了架构师?>>>    Python Challenge是一个网页闯关游戏,通过一些提示找出下一关的网页地址.与众不同的是,它是专门为程序员设计的,因为大多数 ...

  7. Python Challenge 过关心得(0)

    最近开始用Openerp进行开发,在python语言本身上并没有什么太大的进展,于是决定利用空闲时间做一点python练习. 最终找到了这款叫做Python Challenge(http://www. ...

  8. Python challenge 全部题解

    Python Challenge http://www.pythonchallenge.com/ http://garethrees.org/2007/05/07/python-challenge/ ...

  9. 转:一个古老的编程游戏:Python Challenge全通攻略

    Python Challenge是一个网页闯关游戏,通过一些提示找出下一关的网页地址.与众不同的是,它是专门为程序员设计的,因为大多数关卡都要编程来算哦!! 去年和同学一起玩的,他做了大半,我做了小半 ...

  10. [转]一个古老的编程游戏:Python Challenge全通攻略

    Python Challenge是一个网页闯关游戏,通过一些提示找出下一关的网页地址.与众不同的是,它是专门为程序员设计的,因为大多数关卡都要编程来算哦!! 去年和同学一起玩的,他做了大半,我做了小半 ...

最新文章

  1. 512张GPU炼出10万亿参数巨模型!5个月后达摩院模型再升级,今年双十一已经用上了...
  2. 推荐给大家看的设计书
  3. OPPO R9s在哪里开启Usb调试模式的完美步骤
  4. Coursera, Big Data 1, Introduction (week 3)
  5. c#中WebBrowser控件的使用方法
  6. 二分图常用建图方法及其性质
  7. mysql数据库中的int类型_MySQL中int(M)和tinyint(M)数值类型中M值的意义
  8. 大话数据结构——查找
  9. 腾讯面试题: 百度搜索为什么那么快? | 原力计划
  10. 机器学习算法之KNN算法
  11. 朋友,谁会Symbian S40 Symbian S60 v3/v5 Android?
  12. 星星之火-56:前传接口 CPRI容器的字长、能力与CPRI速率的对应关系
  13. 钉钉微应用H5的调试方法
  14. EXCEL快捷键大全(三)(九耶-钛伦特)
  15. linux mc服务器 mod_官方minecraft服务器简单开服方法[linux][minecraft1.5.2]
  16. HDOJ3594-仙人掌图的判断
  17. java mye_JAVA环境搭建之MyEclipse10+jdk1.8+tomcat8环境搭建详解
  18. 《iOS用户体验》总结与思考-修改版
  19. 智能三子棋——保姆级教学。
  20. UDS诊断看这篇就够了,吐血整理

热门文章

  1. 鸡蛋该放在哪些篮子里?多少合适?
  2. java08 Set
  3. 爆气球这道题目,展开了新的思路
  4. Java学习笔记—接口
  5. RHEL 5 设置 YUM
  6. poj1256(贪心+并查集)
  7. Support:Tenjeafan@163.com
  8. LInux初始学习篇:基本命令使用
  9. 关于session为什么要持久化?
  10. Windows Phone 7 网络编程之留言板应用