Python example of adding spaces after each character

不言
Release: 2018-05-07 16:23:18
Original
7407 people have browsed it

This article mainly introduces examples of adding spaces after each character in python. It has certain reference value. Now I share it with you. Friends in need can refer to it

The example is as follows:

#!/usr/bin/env Python
# coding=utf-8
file = open("chinese1.txt",'r')
file2 = open(r'chinese2.txt', 'w')# 返回一个文件对象
list1= file.readlines()
list2 = []
j = -1
for i in list1:
 j+=1
 if j % 3 == 2:
  list1[j] = ("=== \n")
 else:
  list1[j] = i
 # print(j)
 # print(list1[j])
for i in list1:
 file2.write(i)

file.close()
file2.close()
file = open(r'two_1_2.0_100w.txt', 'r')
file2 = open(r"chinese1.txt",'w')
file2.write(' '.join([f+ ' ' for fh in file for f in fh ]))
file.close()
file2.close()
Copy after login

Related recommendations:

Solve the problem of encoding socks5 proxy in Python requests library


The above is the detailed content of Python example of adding spaces after each character. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!