发现自己写python的空格split还挺多坎的,尤其是最后一个是空格的情形:

def split(s):
i = 0
ans = []
while i < len(s):
start = i
# find space
while i < len(s) and s[i] != ' ':
i += 1
ans.append(s[start:i])
i += 1
if s and s[-1] == " ":
ans.append("")
return ans assert split("") == []
assert split(" ") == ["", ""]
assert split(" ") == ["", "", ""]
assert split("a") == ["a"]
assert split("a b") == ["a", "b"]
assert split(" a") == ["", "a"]
assert split("a ") == ["a", ""]
assert split(" a b") == ["", "a", "b"]
assert split("a b ") == ["a", "b", ""]
assert split("ac bcd") == ["ac", "bcd"]

  

最新文章

  1. Lind.DDD.LindAspects方法拦截的介绍
  2. C++哈夫曼树编码和译码的实现
  3. git 教程(11)--从远程库克隆
  4. MySQL表中数据的迁移
  5. CLH锁 、MCS锁
  6. 如何计算oracle数据库内存
  7. 翻译brent ozar的sqlserver dba训练课程——第一章:建立数据库服务器清单
  8. Linux进程笔记
  9. Performing a full database disaster recovery with RMAN
  10. Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)
  11. 《Java4Android视频教程》学习笔记(一)
  12. HDU1002——大整数加法
  13. OC的特有语法-分类Category、 类的本质、description方法、SEL、NSLog输出增强、点语法、变量作用域、@property @synthesize关键字、Id、OC语言构造方法
  14. 四。Hibernate 使用MAVEN工具
  15. Rest Framework
  16. 20165306 Exp2 后门原理与实践
  17. UVA816-Abbott&#39;s Revenge(搜索进阶)
  18. C# 执行bat批处理文件
  19. APP 渠道推广【摘自网络】
  20. 转载:GBDT算法梳理

热门文章

  1. 标准C程序设计七---07
  2. Nginx反向代理新篇-使用location对多个URL做反向代理
  3. 感受lambda之美,推荐收藏,需要时查阅
  4. Matlab中配置VLFeat
  5. hadoop-mapreduce中reducetask执行分析
  6. iOS --- 总结Objective-C中经常使用的宏定义(持续更新中)
  7. grunt 试用笔记
  8. flex中dispatchEvent的用法(自定义事件) .
  9. 新生入学V3.0颗粒归仓
  10. ISC DHCP: Enterprise grade solution for configuration needs