Skip to content

Instantly share code, notes, and snippets.

@Endle
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Endle/c17bc584a0b22c393f1c to your computer and use it in GitHub Desktop.
Save Endle/c17bc584a0b22c393f1c to your computer and use it in GitHub Desktop.
Regular Expression for FUD 2014 Beijing Air Ticket
#!/usr/bin/python3
FILE='asia'
fin = open(FILE, 'r')
strings = fin.readlines()
strings.sort()
strings = [s.strip() for s in strings]
print(strings)
import re
pat = re.compile(r'^([a-zA-Z() .,]+): *([\w $():,¥]+)')
nstrings = [pat.match(s).groups() for s in strings]
print (nstrings)
result = ['|{0} || Beijing || {1}'.format(s[0], s[1]) \
+ '\n|-' for s in nstrings]
fout = open('result', 'w')
for s in result:
print (s, file=fout)
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment