Skip to content

Instantly share code, notes, and snippets.

@zeroxia
Last active May 12, 2016 12:57
Show Gist options
  • Save zeroxia/342c6718514db5c08140fbeea8cfeec0 to your computer and use it in GitHub Desktop.
Save zeroxia/342c6718514db5c08140fbeea8cfeec0 to your computer and use it in GitHub Desktop.
Find lines with equal "left" and "right" parts that are separated by the Chinese comma ","
#!/usr/bin/python3
# vim: set ts=4 et:
import re
p = re.compile("^(.*),(.*)。$")
with open("input.txt") as f:
for lno, line in enumerate(f):
mo = p.match(line.rstrip())
if mo:
if mo.end(1) - mo.start(1) == mo.end(2) - mo.start(2):
print("{:3d}: YES: [{}] == [{}]".format(lno + 1, mo.group(1), mo.group(2)))
else:
print("{:3d}: NO: [{}] != [{}]".format(lno + 1, mo.group(1), mo.group(2)))
# Sample input.txt:
"""
降成本,补短板。
稳中有进,稳中有好。
回顾过去一年,成绩来之不易。
回顾过过去一年,成绩来之bb不易。
提高利用外资水平,继续放宽投资准入。
你好,OK。
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment