Python :替换空格
来源:互联网 发布:网页设计什么软件 编辑:程序博客网 时间:2024/06/15 04:48
牛客网上的剑指 offer的在线编程:
题目描述
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
# -*- coding:utf-8 -*-#import reclass Solution: # s 源字符串 def replaceSpace(self, s): # write code here# 方法一:利用 re 模块 #return re.sub('\s', '%20', s)# 方法二: new_s = [] for item in s: if item == ' ': new_s.append('%20') else: new_s.append(item) return ''.join(new_s)
阅读全文
0 0
- python 刷题:替换空格
- 编程:空格替换Python
- Python :替换空格
- 4替换空格python
- python 空格替换
- python处理文件tab替换成空格
- 剑指offer 算法2 替换空格(python)
- 剑指offer之空格替换(Python)
- 空格替换
- 替换空格
- 空格替换
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 【链表】节点的插入删除【25. Reverse Nodes in k-Group】
- selenium java环境搭建
- kali2017.4添加国内更新源
- Androidstudio和Eclipse ADT引入Fresco
- springmvc 配置swagger ui 生成接口文档
- Python :替换空格
- HDU6025 Coprime Sequence (思路题)
- 模拟实现string 增删查改 比较大小
- idhttp 发送数据格式
- 集合中遍历元素并删除个别元素
- poj 1733 Parity game (类似于HDU 3038可放一起做)
- FX3/CX3 DMA Overview
- Hadoop MapReduce执行过程实例详解
- TI zigbee match and bing