-
Notifications
You must be signed in to change notification settings - Fork 19
/
sample7.py
34 lines (26 loc) · 991 Bytes
/
sample7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
A data cleaning question from NICAR-L
"""
old = """Smith, John
12345 A Street
Colorado Springs CO
County: El Paso
Reason for submission: To go on vacation
Miller, Rebecca
45678 A Street
Colorado Springs CO
County: El Paso
Reason for submission: To take a break"""
new = """
Smith, John 12345 A Street Colorado Springs CO County: El Paso Reason for submission: To go on vacation
Miller, Rebecca 45678 A Street Colorado Springs CO County: El Paso Reason for submission: To take a break
"""
lines = old.split("\n")
for i in xrange(0,len(lines),5): print('\t'.join([x.strip() for x in lines[i:i+5]])+'\n')
"""
# To run on files
with open("old.txt") as old:
with open("new.txt","w") as new:
lines = old.readlines()
for i in xrange(0,len(lines),5): new.write('\t'.join([x.strip() for x in lines[i:i+5]])+'\n')
"""