Python快速入门(2)练习题
来源:互联网 发布:淘宝领取虾米会员 编辑:程序博客网 时间:2024/05/17 22:26
# C. fix_start
# Given a string s, return a string
# where all occurences of its first char have
# been changed to '*', except do not change
# the first char itself.
# e.g. 'babble' yields 'ba**le'
# Assume that the string is length 1 or more.
# Hint: s.replace(stra, strb) returns a version of string s
# where all instances of stra have been replaced by strb.
# Given a string s, return a string
# where all occurences of its first char have
# been changed to '*', except do not change
# the first char itself.
# e.g. 'babble' yields 'ba**le'
# Assume that the string is length 1 or more.
# Hint: s.replace(stra, strb) returns a version of string s
# where all instances of stra have been replaced by strb.
def fix_start(s): # +++your code here+++ # LAB(begin solution) front = s[0] back = s[1:] fixed_back = back.replace(front, '*') return front + fixed_back
# E. not_bad
# Given a string, find the first appearance of the
# substring 'not' and 'bad'. If the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# Return the resulting string.
# So 'This dinner is not that bad!' yields:
# This dinner is good!
def not_bad(s): # +++your code here+++ # LAB(begin solution) n = s.find('not') b = s.find('bad') if n != -1 and b != -1 and b > n:s = s[:n] + 'good' + s[b+3:] return s
0 0
- Python快速入门(2)练习题
- Python快速入门(3)列表、练习题
- python 入门-练习题
- python快速入门(2)List
- 2、Python Requests快速入门
- Python快速入门2--数据结构
- python快速入门(一)
- **Python快速入门(一)**
- Python 快速入门(二)
- Python学习笔记2:Python快速入门
- Python练习题2
- Python练习题(2)
- python练习题(一)
- python(1)练习题
- Python快速入门(2)-函数的魔法
- python 进阶学习之5--入门练习题
- python快速学习帖!(入门专用)
- Python快速入门(5)正则表达式
- 谈早些年的QQ网盘现如今的微云 - 是生不逢时呢,还是没挑好时侯出生呢?!
- 谷歌浏览器设置及常用快捷键
- 第1章 Android应用与开发环境
- 顺炮直车两头蛇对横车平边炮
- LeetCode OJ:Combinations
- Python快速入门(2)练习题
- 正则表达式的基本知识
- 《Thinking In Algorithm》07.Red-Black Trees(红黑树)
- 树莓派串口配置
- 一个以可视化界面的方式管理与调度Hadoop的作业平台——Zeus
- 待了解和所爱的
- SGI STL内存配置器Allocator
- 浅谈排序算法学习之基数排序,又称桶子排序(二)
- ZOJ-2680