"list" in python
2014-01-20 16:49
399 查看
用python写了一个小脚本,用来去除文本文件中多余的空格,感觉python里字符串或数组的索引很有意思。
索引可正可负,也有类似于Matlab中的步长。特别注意的是,使用索引进行分片时,第一个索引是需要提取部分的第一个元素的索引值,而最后的索引则是分片之后右侧剩下部分的第一个元素的索引[1]。
Ref:
[1] /article/5461203.html
索引可正可负,也有类似于Matlab中的步长。特别注意的是,使用索引进行分片时,第一个索引是需要提取部分的第一个元素的索引值,而最后的索引则是分片之后右侧剩下部分的第一个元素的索引[1]。
# to remove the redundant space in each line newFile = open("dst","w",encoding="UTF-8") with open("src.txt",encoding="UTF-8") as f: for line in f: pos = line.index(' ') n = len(line) line1 = line[0:pos] line2 = line[pos+1:n] line = line1 + line2 newFile.write(line) newFile.close()
Ref:
[1] /article/5461203.html
相关文章推荐
- "Argument list too long": Beyond Arguments and Limitations
- <s:radio list="%{#answerForms}" name="answers" ></s:radio>
- "Argument list too long": Beyond Arguments and Limitations
- distinguish "list" & "array" in python
- <include layout="@*android:layout/preference_list_settings_header" />
- "c++ list", c++链表遇上的问题
- <c:foreach var="detail" items="${mailManager.detailList}" varStatus="status"
- <ListView android:id="@+id/android:list" 在 list 前加 android: 的原因
- 关于spark中的"pyspark.resultiterable.ResultIterable" to a list
- "Image → PngFile" Cache
- 3.字符反转 输入一串字符,比如"abcd",以倒序的方式将它打印出来
- "error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- "冬天"快乐,带你进入Hibernate
- "控件必须放在具有 runat=server 的窗体标记内"错误的解决方法
- "真实"和"谎言"
- Java出现"此时不应有......."的错误
- 什么是 "asmlinkage"?
- SQLServer2008中恼人的"阻止保存要求重新创建表的更改"
- "盗梦空间"观感(程序员角度)
- 【c++笔记七】教你使用"const类型的对象、成员函数"和"static类型的成员函数、变量"